vue + elementui 中的彈窗組件封裝成公共組件


1. 第一步

<template>
  <div class="tip">
    <el-dialog title="提示"
               :visible="dialogVisible"
               width="30%">
      <span>{{msg}}</span>
      <span slot="footer"
            class="dialog-footer">
        <el-button @click="clear">取 消</el-button>
        <el-button type="primary"
                   @click="sure">確 定</el-button>
      </span>
    </el-dialog>
  </div>
</template>
<script>
export default {
  data () {
    return {
    }
  },
  props: {
    dialogVisible: {
      type: Boolean,
      default: false
    },
    msg: {
      type: String,
      default: '是否退出頁面'
    }
  },
  methods: {
    clear () {
      this.$emit('clear', false);
    },
    sure () {
      this.$emit('sure', false);
      this.$router.push('/register');
    }
  }
}
</script>
<style lang="scss">
</style>

2. 第二步

import MsgTip from './msgTip.vue';
const tip = {};
tip.install = function (vue) {
  vue.component('MsgTip', MsgTip);
}
export default tip;

3. 在全局中導入

 

 4. 在組件中使用

 

 

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM