Below I will share with you a method of setting global variables or data in vue. It has a good reference value and I hope it will be helpful to everyone.
The example is as follows:
const MyPlugin = { // install方法是必需的 // // 包含两个参数:Vue 构造器,一个可选的选项对象 install(Vue, options) { Vue.prototype.test = "test" ; Vue.prototype.wechat = "my wechat!"; } }; export default MyPlugin
This method can start a separate file and import it When you go to the required page, you can use the vue instance to get the corresponding data. After use like the following, the method of getting the data is the same as getting the data in the data in each module
import MyPligin from './**/api'; //引入全局变量 Vue.use(MyPligin);
The above is what I compiled for everyone. I hope it will be helpful to everyone in the future.
Related articles:
DOM event binding analysis in js
How to perfectly parse data in js
Solve the problem of failure after using vue.js routing
##
The above is the detailed content of Set global variables or data methods according to vue (detailed tutorial). For more information, please follow other related articles on the PHP Chinese website!