1、父组件传值给子组件,子组件不修改该值:
子组件:
props: [ "ftname"],
<el-row>
<el-col :span="24">{{ this.ftname }}</el-col>
</el-row>
父组件:
1、
<ftnodeinfoVue :ftname="ftname"></ftnodeinfoVue>
2、
export default {
data() {
return {
ftname: "",
2、父组件传值给子组件,子组件修改该值,但不需要传回:
需要使用watch,而不是data;
子组件:
1、
props: ["dialogTableVisible"],
2、data() {
return {
dialogTableVisibleSelf: "默认值",
#下面的方法,无法把prop复制给data:
#dialogTableVisibleSelf: this.dialogTableVisible,
#因为:data会优先于prop;所以,data初始值是“默认值”;
#且data赋值不是响应式的;因此prop的改变,不会造成data的修改;
#因此需要使用watch
3、
watch: {
// 如果需要第一次就执行监听 则需要设置:immediate: true
dialogTableVisible: {
handler(newVal, oldVal) {
this.dialogTableVisibleSelf = this.dialogTableVisible;
},
或使用computed:
computed: {
dialogTableVisibleSelf () {
return this.dialogTableVisible;
},
},
4、
<el-dialog title="收货地址" :visible.sync="dialogTableVisibleSelf">
父组件:
1、 <ftnodeinfoVue
:dialogTableVisible="dialogTableVisibleParent"
2、
export default {
data() {
return {
dialogTableVisibleParent: false,