参考:https://juejin.im/post/59eddbfe6fb9a0450908abb4
定义
global.js
let name = '小明'
exports.install = function (Vue, options) {
Vue.prototype.name = name
Vue.prototype.text1 = function () {
alert('执行成功1')
}
Vue.prototype.text2 = function () {
alert('执行成功2')
}
}
引用
main.js
import Global from './components/global'
Vue.use(Global)
vue页面使用
<template>
<div id="app">
{{name}}
<router-view/>
</div>
</template>
<script>
export default {
name: 'App',
data () {
return {
name: this.name
}
},
mounted () {
this.text1()
}
}
</script>