当前位置:网站首页>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
// ......
});
边栏推荐
- C#绘制带控制点的Bezier曲线,用于点阵图像及矢量图形
- [daiy4] jz32 print binary tree from top to bottom
- Applet (subcontracting)
- Codeforces round 684 (Div. 2) e - green shopping (line segment tree)
- Kubedm series-00-overview
- Alibaba cloud sends SMS verification code
- Configuration and startup of kubedm series-02-kubelet
- C#【必备技能篇】ConfigurationManager 类的使用(文件App.config的使用)
- Rebuild my 3D world [open source] [serialization-3] [comparison between colmap and openmvg]
- Meta标签详解
猜你喜欢
[daiy4] copy of JZ35 complex linked list
nodejs_ 01_ fs. readFile
Ros-10 roslaunch summary
深度学习模型与湿实验的结合,有望用于代谢通量分析
嗨 FUN 一夏,与 StarRocks 一起玩转 SQL Planner!
Introduction Guide to stereo vision (7): stereo matching
Use and programming method of ros-8 parameters
[code practice] [stereo matching series] Classic ad census: (6) multi step parallax optimization
牛顿迭代法(解非线性方程)
Introduction Guide to stereo vision (6): level constraints and polar correction of fusiello method
随机推荐
Ecmascript6 introduction and environment construction
. Net service governance flow limiting middleware -fireflysoft RateLimit
Introduction Guide to stereo vision (1): coordinate system and camera parameters
牛顿迭代法(解非线性方程)
Nodemon installation and use
520 diamond Championship 7-4 7-7 solution
Introduction Guide to stereo vision (3): Zhang calibration method of camera calibration [ultra detailed and worthy of collection]
Array, date, string object method
Halcon affine transformations to regions
多元线性回归(sklearn法)
Introduction Guide to stereo vision (6): level constraints and polar correction of fusiello method
Ros-10 roslaunch summary
LLVM之父Chris Lattner:为什么我们要重建AI基础设施软件
Codeworks round 638 (Div. 2) cute new problem solution
Introduction Guide to stereo vision (5): dual camera calibration [no more collection, I charge ~]
什么是防火墙?防火墙基础知识讲解
Characteristic Engineering
Kubedm series-00-overview
2020 "Lenovo Cup" National College programming online Invitational Competition and the third Shanghai University of technology programming competition
C#【必备技能篇】ConfigurationManager 类的使用(文件App.config的使用)