element ui el-dialog

data(){
dialogVisible: false
}
<el-button
  icon="el-icon-caret-right"
  size="mini"
  class="table_button"
  @click="handlePlay(scope.row)"
  >播放</el-button>
handlePlay(row) {
      if (row.recording) {
        this.play();
      } else {
        this.$message({
          message: "播放失败!管理员似乎没有上传录音!",
          type: "warning",
        });
      }
    }
play() {
      this.dialogVisible = true;
      this.$nextTick(() => {
        this.$refs.audio.play();
      });
    }
<el-dialog
                title="录音播放"
                :visible.sync="dialogVisible"
                :before-close="stop"
              >
                <template>
                  <center>
                    <audio
                      :src="src"
                      :autoplay="autoplay"
                      :controls="controls"
                      style="width: 500px"
                      ref="audio"
                    >
                      Your browser does not support the audio element.
                    </audio>
                  </center>
                </template>
              </el-dialog>

为什么visible属性要加上sync修饰符

阅读 1.5k
1 个回答

https://cn.vuejs.org/v2/guide...

el-dialog组件中点击关闭按钮或者取消按钮,会关闭他里面控制弹框的变量,并调用this.$emit('update:visible', false)通知父组件,如果父组件不加sync就不能自动修改父组件visible的值,数据会有冲突,再次打开弹框,会打不开,因为visible还是true

撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题