Tencent Cloud Micro-Code realizes parameter passing between pages mainly through the following ways:
pageA and want to pass a parameter userId with a value of 123 to pageB. In pageA, you can use the following code to navigate to pageB:// Assume there is a navigation function in Micro - Code
navigateTo({
url: '/pages/pageB/pageB?userId=123'
});
In pageB, you can use the following code to get the parameter:
// Get the URL parameters
const pages = getCurrentPages();
const currentPage = pages[pages.length - 1];
const options = currentPage.options;
const userId = options.userId;
console.log(userId); // Output: 123
// In the app.js file, define a global object
App({
globalData: {
userInfo: null
}
});
In pageA, you can set the value of the global variable:
const app = getApp();
app.globalData.userInfo = {
name: 'John',
age: 30
};
navigateTo({
url: '/pages/pageB/pageB'
});
In pageB, you can get the value of the global variable:
const app = getApp();
const userInfo = app.globalData.userInfo;
console.log(userInfo); // Output: {name: 'John', age: 30}
If you want to build and deploy such applications on the cloud, Tencent Cloud provides a variety of services. For example, Tencent Cloud's Object Storage can be used to store static resources such as images and files for the application. Tencent Cloud Serverless Cloud Function can be used to handle some backend logic, such as data processing and API calls, which can better support the operation of the application with parameter - passing function between pages.