In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-09-21 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/02 Report--
This article introduces the knowledge of "how to use kbone to achieve cross-page communication and cross-page data sharing". In the operation of actual cases, many people will encounter such a dilemma. Next, let the editor lead you to learn how to deal with these situations. I hope you can read it carefully and be able to achieve something!
1.1 subscribe to broadcast messages on the page / / Page 1
Window.$$subscribe ('hello', data = > {)
Console.log ('receive a msg:', data)
})
1.2 publish broadcast messages on other pages / / Page 2
Window.$$publish ('hello',' I am june')
Receive a msg: I am june is output on the page that subscribes to this message.
PS: if you need to unsubscribe to a message, you can use the window.$$unsubscribe API to cancel it.
PS: when the page is closed, all subscriptions to the page will be cancelled.
If you need to share data across pages, you can use the window.$$global object, and the window.$$global of all pages will point to the same object:
/ / Page 1
Window.$$global.name = 'june'
/ / Page 2
Console.log (window.$$global.name) / / output june
PS: for more information on API, please see the dom/bom extended API documentation.
2. Case
Create the 08-share-message directory under the kbone-advanced directory, and this case is completed under this directory.
2.1Create package.jsoncd 08-share-message
Npm init-y
Edit package.json:
{
"scripts": {
"mp": "cross-env NODE_ENV=production webpack-config build/webpack.mp.config.js-progress-hide-modules"
}
"dependencies": {
"vue": "^ 2.5.11"
"vuex": "^ 3.1.3"
}
"browserslist": [
"> 1%"
"last 2 versions"
"not ie
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
The market share of Chrome browser on the desktop has exceeded 70%, and users are complaining about
The world's first 2nm mobile chip: Samsung Exynos 2600 is ready for mass production.According to a r
A US federal judge has ruled that Google can keep its Chrome browser, but it will be prohibited from
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
About us Contact us Product review car news thenatureplanet
More Form oMedia: AutoTimes. Bestcoffee. SL News. Jarebook. Coffee Hunters. Sundaily. Modezone. NNB. Coffee. Game News. FrontStreet. GGAMEN
© 2024 shulou.com SLNews company. All rights reserved.