当前位置:网站首页>Uni app implements global variables
Uni app implements global variables
2022-07-05 09:07:00 【Hang Hang Dad】
4、globalData
Applet can be used in App Statement above Global variables , But in Vue There is no ,uni-app In the App.vue Can be defined in globalData Attribute , Can also be used API Read and write this value .
This way supports vue and nvue Shared data . Is currently the nvue and vue A better way to share data .
1, Definition :App.vue Define methods or variables
<script> export default { globalData: { text: 'text' }, onLaunch: function() { console.log('App Launch') }, onShow: function() { console.log('App Show') }, onHide: function() { console.log('App Hide') } } </script> <style> /* Every page is public css */ </style>
2, Operation in page globalData The way
assignment :
getApp().globalData.text = 'test'
Value :
console.log(getApp().globalData.text)
Use cases :
import app from "../../App.vue" /// This sentence is more important You can try Delete and add this sentence
// there vm, Is that we are vue In the document this, So we can get it here vuex The variable of , Like what's in it token Variable
const install = (Vue, vm) => {
// This is a custom configuration parameter , See the above description for specific parameters
Vue.prototype.$u.http.setConfig({
baseUrl: app.globalData.apiUrl,
loadingText: 'loading...',
loadingTime: 300,
originalData: false, // Whether to return the original data of the server in the interceptor
loadingMask: true, // Exhibition loading When , Whether to give a transparent mask , Prevent touch penetration
// ......
});
边栏推荐
- Halcon clolor_ pieces. Hedv: classifier_ Color recognition
- nodejs_ fs. writeFile
- Introduction Guide to stereo vision (2): key matrix (essential matrix, basic matrix, homography matrix)
- 12. Dynamic link library, DLL
- Blue Bridge Cup provincial match simulation question 9 (MST)
- Install the CPU version of tensorflow+cuda+cudnn (ultra detailed)
- Use arm neon operation to improve memory copy speed
- Codeworks round 638 (Div. 2) cute new problem solution
- Redis implements a high-performance full-text search engine -- redisearch
- C#【必备技能篇】ConfigurationManager 类的使用(文件App.config的使用)
猜你喜欢
Use and programming method of ros-8 parameters
Add discount recharge and discount shadow ticket plug-ins to the resource realization applet
Halcon Chinese character recognition
Halcon color recognition_ fuses. hdev:classify fuses by color
2020 "Lenovo Cup" National College programming online Invitational Competition and the third Shanghai University of technology programming competition
Applet (use of NPM package)
[Niuke brush questions day4] jz55 depth of binary tree
Codeworks round 639 (Div. 2) cute new problem solution
Redis implements a high-performance full-text search engine -- redisearch
Nodemon installation and use
随机推荐
Halcon Chinese character recognition
Beautiful soup parsing and extracting data
多元线性回归(梯度下降法)
Meta tag details
Mengxin summary of LIS (longest ascending subsequence) topics
How many checks does kubedm series-01-preflight have
[beauty of algebra] solution method of linear equations ax=0
TF coordinate transformation of common components of ros-9 ROS
深入浅出PyTorch中的nn.CrossEntropyLoss
RT-Thread内核快速入门,内核实现与应用开发学习随笔记
Wechat H5 official account to get openid climbing account
Programming implementation of subscriber node of ROS learning 3 subscriber
Kubedm series-00-overview
Codeworks round 681 (Div. 2) supplement
Huber Loss
Driver's license physical examination hospital (114-2 hang up the corresponding hospital driver physical examination)
Multiple solutions to one problem, asp Net core application startup initialization n schemes [Part 1]
File server migration scheme of a company
RT thread kernel quick start, kernel implementation and application development learning with notes
np. allclose