标签:实现 ops mit 改变 for val pre 传递 跨域
父子组件之间的通信属于传递私有数据,比较容易理解
<!--父组件-->
<template>
<span>父组件:</span>
<input type="text" v-model="pVal">
<son :textP=‘pVal‘></son>
</template>
<script>
export default {
data() {
return {
pVal: 12
};
}
</script>
<!--子组件 son-->
<template>
<div class="props">
<span>子组件:</span>
<input type="text" v-model="textP">
</div>
</template>
<script>
export default {
props: ["textP"]
};
</script>
<!--父组件-->
<template>
<son @pMethod=‘show‘></son>
</template>
<script>
export default {
data() {
return {
pVal: 12
};
},
methods: {
show(data) {
this.pVal = data;
}
}
};
</script>
<!--子组件-->
<template>
<div class="props">
<span>子组件:</span>
<button @click="change">点击改变父组件的值</button>
</div>
</template>
<script>
export default {
methods: {
change() {
this.$emit("pMethod", 19);
}
}
};
</script>
关于子组件向父组件传值,其形式上与 jsonp 类似,服务器将想要传递的数据通过一个 callback 方法传参的形式最终达到跨域传值的目的
其实这样的形式也十分类似 winform 里面的不同窗口之间的传值,也是通过方法传递参数
标签:实现 ops mit 改变 for val pre 传递 跨域
原文地址:https://www.cnblogs.com/cnloop/p/9278984.html