Vue2 通过.sync修饰符实现数据双向绑定

App.vue

html 复制代码
<template>
  <div class="app">
    <button
    v-on:click='isShow=true'
    >退出按钮</button>
    <BaseDialog
    :visible.sync='isShow'
    ></BaseDialog>
  </div>
</template>

<script>
import BaseDialog from "./components/BaseDialog.vue"
export default {
  data() {
    return {
      isShow:false,
    }
  },
  methods: {
    
  },
  components: {
    BaseDialog,
  },
}
</script>

<style>
</style>

BaseDialog.vue

html 复制代码
<template>
<!-- 通过v-show -->
  <div class="base-dialog-wrap" v-show='visible'>
    <div class="base-dialog">
      <div class="title">
        <h3>温馨提示:</h3>
        <button v-on:click='close' class="close">x</button>
      </div>
      <div class="content">
        <p>你确认要退出本系统么?</p>
      </div>
      <div class="footer">
        <button v-on:click='close'>确认</button>
        <button >取消</button>
      </div>
    </div>
  </div>
</template>

<script>
export default {
  props:{
    visible:Boolean
  },
  methods:{
    close(){
      this.$emit('update:visible',false)
    }
  }
}
</script>

<style scoped>
.base-dialog-wrap {
  width: 300px;
  height: 200px;
  box-shadow: 2px 2px 2px 2px #ccc;
  position: fixed;
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%);
  padding: 0 10px;
}
.base-dialog .title {
  display: flex;
  justify-content: space-between;
  align-items: center;
  border-bottom: 2px solid #000;
}
.base-dialog .content {
  margin-top: 38px;
}
.base-dialog .title .close {
  width: 20px;
  height: 20px;
  cursor: pointer;
  line-height: 10px;
}
.footer {
  display: flex;
  justify-content: flex-end;
  margin-top: 26px;
}
.footer button {
  width: 80px;
  height: 40px;
}
.footer button:nth-child(1) {
  margin-right: 10px;
  cursor: pointer;
}
</style>
相关推荐
njsgcs4 小时前
safari局域网读电脑地址,第一次读的到,重载之后就不行,得重启。.local解决办法
前端·电脑·safari
Lank_M4 小时前
超分分块为什么按后端分:160与96的取舍
前端
流星。。方4 小时前
企业官网前端组件怎么拆?从落地页到内容页的分层思路
前端
deli0074 小时前
豹纹和斑马纹是怎么长出来的:调两个参数,花纹自己浮现
前端
进击的明明4 小时前
TypeScript速通笔记(上)
前端·面试·typescript
deli0074 小时前
萤火虫为什么会一起闪:调一个耦合系数,整片林子自己同步
前端
计算机魔术师4 小时前
英伟达联合超100家伙伴推出开放代理安全平台
前端
看谷秀4 小时前
arkts-12 鸿蒙生态/卡片
前端·arkts
朱 欢 庆4 小时前
el-table-v2 虚拟表格组件
前端·javascript·vue.js
创新技术阁4 小时前
FastapiAdmin代码生成详细解释
前端·后端·fastapi