当前位置:网站首页>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
// ......
});
边栏推荐
猜你喜欢
Generate confrontation network
AUTOSAR从入门到精通100讲(103)-dbc文件的格式以及创建详解
编辑器-vi、vim的使用
Rebuild my 3D world [open source] [serialization-2]
Multiple solutions to one problem, asp Net core application startup initialization n schemes [Part 1]
Introduction Guide to stereo vision (4): DLT direct linear transformation of camera calibration [recommended collection]
It cold knowledge (updating ing~)
C#【必备技能篇】ConfigurationManager 类的使用(文件App.config的使用)
优先级队列(堆)
Halcon: check of blob analysis_ Blister capsule detection
随机推荐
OpenFeign
. Net service governance flow limiting middleware -fireflysoft RateLimit
Array, date, string object method
Array,Date,String 对象方法
golang 基础 ——map、数组、切片 存放不同类型的数据
Ecmascript6 introduction and environment construction
Multiple solutions to one problem, asp Net core application startup initialization n schemes [Part 1]
Introduction Guide to stereo vision (1): coordinate system and camera parameters
Codeforces Round #648 (Div. 2) D. Solve The Maze
编辑器-vi、vim的使用
Pearson correlation coefficient
Halcon color recognition_ fuses. hdev:classify fuses by color
kubeadm系列-02-kubelet的配置和启动
AUTOSAR从入门到精通100讲(103)-dbc文件的格式以及创建详解
Generate confrontation network
利用请求头开发多端应用
什么是防火墙?防火墙基础知识讲解
Halcon affine transformations to regions
JS asynchronous error handling
asp. Net (c)