美文网首页Vue.js前端Vue专辑Vue.js专区
[轮子]element-ui 封装dialog组件

[轮子]element-ui 封装dialog组件

作者: 一人创客 | 来源:发表于2019-09-29 22:09 被阅读0次
        <template>
      <div>
        <el-dialog
          title="title"
          :visible.sync="visible"
          @close="$emit('update:show', false)"
          :show="show"
          :close-on-click-modal="false"
        >
          <el-form ref="form" :model="formData" label-width="80px" v-if="formData">
            <el-form-item label="活动名称">
              <el-input v-model="formData.name"></el-input>
            </el-form-item>
          </el-form>
          <span slot="footer" class="dialog-footer">
            <el-button @click="visible = false">取 消</el-button>
            <el-button type="primary" @click="visible = false">确 定</el-button>
          </span>
        </el-dialog>
      </div>
    </template>
     
    <script>
    export default {
      data() {
        return {
          visible: this.show,
          formData:this.formData
        }
      },
      props: {
        show: {
          type: Boolean,
         formData:Object
        }
      },
      watch: {
        show() {
          this.visible = this.show
          console.log(this.show)
        }
      }
    }
    </script>
    
    

    使用组件

    <template>
        <div>
            <service-dialog :show.sync="show"></service-dialog>
            <el-button @click="open">click</el-button>
        </div>
    </template>
     
    <script>
        import serviceDialog from './serviceDialog'
     
        export default {
            data () {
                return {
                    show: false
                };
            },
            methods: {
                open () {
                    this.show = true;
                }
            },
            components: {
                serviceDialog
            }
        };
    </script>
    

    相关文章

      网友评论

        本文标题:[轮子]element-ui 封装dialog组件

        本文链接:https://www.haomeiwen.com/subject/yybqpctx.html