In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-02-28 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.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.