Home > Web Front-end > JS Tutorial > body text

Set global variables or data methods according to vue (detailed tutorial)

亚连
Release: 2018-05-31 14:56:11
Original
2135 people have browsed it

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
Copy after login

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);
Copy after login

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!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!