vue2全局挂载属性在js和vue文件中使用

45 阅读1分钟

情景一:组件(ant-design-vue)中自带的全局属性

//js文件中伪代码
import Vue from 'vue'
Vue.prototype.$message.success('复制成功')
//vue文件中
this.$message.success('复制成功')

情景二: 挂载,然后使用

//main.js
Vue.prototype.$pre="pre_"
//使用
//js文件中
Vue.prototype.$pre
//在vue文件中
this.$$pre