Use globalData function to set the global variable

Set parameters global variables needed in app.js, such as company name, etc.

//app.js
App({
    globalData: {
        title: 'tomatocc'
    }
})

Then you can (such as index.js) of data inside the array to direct the use of global variables app.js configured in the js file a page.

Page({
    data: {
        text: getApp().globalData.title
    }
})
或者
const app = getApp();
Page({
    data:{
        text:app.title
    }
})

 

 

 

 

 

 

.

Guess you like

Origin www.cnblogs.com/jianxian/p/11111463.html