编程开源技术交流,分享技术与知识

网站首页 > 开源技术 正文

超高效 Vue 模态弹出框组件Vue-Modal

wxchong 2024-07-18 09:34:52 开源技术 11 ℃ 0 评论

今天给大家推荐一款超美观的pc端vue.js弹窗组件VueJsModal。

vue-js-modal 基于Vue构建的Modal对话框组件。单独组件,方便使用。支持拖拽、缩放、异步调用组件。

安装

$ npm i vue-js-modal -S

引入组件

// 在main.js中引入
import Vue from 'vue'
import VModal from 'vue-js-modal'
import 'vue-js-modal/dist/styles.css'
Vue.use(VModal)

调用方式

<template>
  <modal name="example"
    :width="300"
    :height="300"
    :resizable="true"
    :draggable="true"
    :adaptive="true"
    @before-open="beforeOpen"
    @opened="Opened"
    @before-close="beforeClose"
    @closed="Closed"
  >
    Hello, VueModal!
  </modal>
</template>
<script>
export default {
  data() {
    return {}
  },
  mounted() {
    this.$modal.show('example')
  },
  methods: {
    beforeOpen(event) {
      console.log('Opening...')
    },
    Opened(event) {
      console.log('Opened...')
    },
    beforeClose(event) {
      console.log('Closing...')
    },
    Closed(event) {
      console.log('Closed...')
    }
  }
}
</script>

调用内部 show、hide 方法显示和隐藏弹窗

<template>
  <modal name="my-first-modal">
    This is my first modal
  </modal>
</template>

<script>
export default {
  mounted () {
    this.show()
  },
  methods: {
    show () {
      this.$modal.show('my-first-modal');
    },
    hide () {
      this.$modal.hide('my-first-modal');
    }
  }
}
</script>

另外还支持Modal动态调用组件

import MyComponent from './MyComponent.vue'
this.$modal.show(
  MyComponent,
  { text: 'This text is passed as a property' },
  { draggable: true }
)

// or

this.$modal.show(
  {
    template: `
      <div>
        <h1>This is created inline</h1>
        <p>{{ text }}</p>
      </div>
    `,
    props: ['text']
  },
  { text: 'This text is passed as a property' },
  { draggable: true, resizable: true },
  { 'before-close': event => {} }
)


附上模态框示例及仓库地址

# demo地址
http://vue-js-modal.yev.io/

# 项目地址
https://github.com/euvl/vue-js-modal

ok,这次就分享到这里。如果大家有其它Vue弹窗组件,欢迎留言讨论~

Tags:

本文暂时没有评论,来添加一个吧(●'◡'●)

欢迎 发表评论:

最近发表
标签列表