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>
相关推荐
用户47949283569152 分钟前
node_modules 太胖?用 Node.js 原生功能给依赖做一次大扫除
前端·后端·node.js
_Kayo_12 分钟前
TypeScript 学习笔记2
前端·javascript·typescript
海纳百川本尊7606414 分钟前
Flutter框架核心原理深度解析
前端
Shaneyxs15 分钟前
从 0 到 1 实现CloudBase云开发 + 低代码全栈开发活动管理小程序(12)
前端
渔_23 分钟前
uni-app 图片预览 + 长按保存,超实用!
前端
八哥程序员23 分钟前
从DOM结构到布局流:display: content的深度解析与实战应用
前端·css
Shaneyxs23 分钟前
从 0 到 1 实现CloudBase云开发 + 低代码全栈开发活动管理小程序(07)
前端
Shaneyxs25 分钟前
从 0 到 1 实现CloudBase云开发 + 低代码全栈开发活动管理小程序(10)
前端
Shaneyxs26 分钟前
从 0 到 1 实现CloudBase云开发 + 低代码全栈开发活动管理小程序(05)
前端