vue.js - 在 Vue 上显示模态
问题描述
尝试使用以下代码显示模式:
import VModal from 'vue-js-modal';
Vue.use(VModal);
在模板上:
<modal name="hello-world">
hello, world!
</modal>
Vue部分:
myMethod() {
this.$modal.show('hello-world');
}
尝试调用 myMethod() 时,出现错误“无法读取未定义的属性‘显示’”。有任何想法吗?
解决方案
这在 vue-cli 简单环境中对我有用,并且工作正常,经过测试
main.js
import App from "./App.vue";
import Vue from "vue";
import VModal from "vue-js-modal";
Vue.use(VModal);
Vue.config.productionTip = false;
new Vue({
render: h => h(App)
}).$mount("#app");
应用程序.vue
<template>
<div id="app">
<h3>Hello world test</h3>
<modal name="hello-world">
hello, world!
</modal>
<button @click="showModal">show modal</button>
</div>
</template>
<script>
export default {
methods: {
showModal() {
this.$modal.show("hello-world");
}
}
};
</script>
<style lang="scss">
</style>
推荐阅读
- c++ - Clang 工具(clang-tidy、iwyu 等)的单遍运行以及编译?
- matlab - fmincon:优化 MPC 的问题
- reactjs - 为什么我需要在 `useEffect` 中定义事件处理程序 `handleStatusChange`?
- r - 在 levelplot 中每种颜色的中间放置刻度
- java - 无法使用 geoTools 获取 FeaturesCollection 中的内容
- flutter - 删除 Firebase 存储中的所有文件
- laravel - Laravel 部署 - 从 git 部署时避免覆盖存储目录
- angular8 - Angular 8 npm 安装失败
- jquery - jquery的自动完成事件问题
- jenkins - Jenkins 构建中的 Npm 测试需要 8 小时