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/01 Report--
This article mainly introduces the example analysis of vue state sharing, which is very detailed and has certain reference value. Friends who are interested must finish it!
State sharing
With the refinement of components, we will encounter the situation of multi-component state sharing. Vuex can certainly solve these problems, but as stated in the official Vuex documentation, if the application is not large enough, it is best not to use it in order to avoid tedious and redundant code. Today we are introducing the newly added Observable API of vue.js 2.6. by using this api, we can deal with some simple cross-component data state sharing situations.
In the following example, we will create a store outside the component, and then use the store and mutation methods provided by store.js in the App.vue component, as well as other components, so that multiple components can share data state.
First create a store.js that contains a store and a mutations to point to data and processing methods, respectively.
Import Vue from "vue"; export const store = Vue.observable ({count: 0}); export const mutations = {setCount (count) {store.count = count;}}
Then introduce the store.js into the App.vue and use the introduced data and methods in the component
Count: {{count}}
+ 1-1import {store, mutations} from ". / store"; export default {name: "App", computed: {count () {return store.count;}}, methods: {setCount: mutations.setCount}}; these are all the contents of the article "sample Analysis of vue State sharing". Thank you for reading! Hope to share the content to help you, more related knowledge, welcome to follow the industry information channel!
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.