首页 > 其他 > 详细

vue之弹出框传值问题

时间:2019-07-31 09:50:39      阅读:230      评论:0      收藏:0      [点我收藏+]

 

发现问题:将 dialogStatus 值定义在 data 里,出现第一次进入弹出框页面 dialogStatus 值为空,第二次进入时 dialogStatus 有值。

在一个vue页面,进入另一个弹出框定义的vue(传入dialogStatus值)时,我遇到第一次进入弹出框页面dialogStatus值为空,第二次进入时值传过去了。

代码:

vue页面:

<el-dialog :title="textMap[dialogStatus]" size="large" :visible.sync="dialogFormVisible">
      <modify @closeStationDialog="closeStationDialog" :dialogStatus="dialogStatus" ref="modify"></modify>
</el-dialog>
export default {
   components: {
    ‘modify‘: () => import(‘./components/modify‘)
  },
  methods: {
      handleAdd(){
          this.dialogStatus = ‘create‘;
          this.dialogFormVisible = true;
          console.log(this.$refs.modify);
          if (this.$refs.modify !== undefined) {
            this.$refs.modify.dialogStatus = this.dialogStatus;
          }
      }
   }
}

modify页面(弹出框页面):

<div style="text-align: center; margin-bottom: 1rem;">
     <el-button @click="cancel(‘form‘)">取 消</el-button>
     <el-button v-if="dialogStatus==‘create‘" type="primary" @click="create(‘form‘)">确 定</el-button>
     <el-button v-else type="primary" @click="update(‘form‘)">确 定</el-button>
</div>
export default {
    data(){
       return{
          dialogStatus: ‘‘
       }
  }
}

发现问题:将 dialogStatus 值定义在 data 里,出现第一次进入弹出框页面 dialogStatus 值为空,第二次进入时 dialogStatus 有值。
解决办法:将 dialogStatus(需要传递的值)定义在 props 里。

export default {
props: {
dialogStatus: {
default: ‘1‘
}
}
}

 

vue之弹出框传值问题

原文:https://www.cnblogs.com/braveLN/p/11273882.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!