Vue this.$store.state.xx.xxthis.$store.state.xx.xx is actually the state management tool Vuex used by Vue Vuex official website: https://vuex.vuejs.org/zh/ It feels like extracting the shared state of the components and managing it in a global singleton mode. In this mode, our component tree forms a huge "view", and any component can obtain state or trigger behavior no matter where it is in the tree! (You can access and modify it dynamically at any time anywhere in the project. After the modification, Vue will update your entire project) Get data from the storeRegister the store in the vue root file so that all components can use the data in the store My project file structureRegister the store in the main.js file Then the code is written After logging in, the front end caches the userId, and then searches through the userId This position is used in the public page Summary: main.js is the guild boss. You give the reward to the boss, and the boss will give you some props to use, so you can use them through this. When do Vue projects use store.state, $store.state and this.$store.sstore and [this.]$storeIn short, if you inject the store into the root component, you can use this.$store.xxxx directly in all .vue files. Vue official website: In order to access this.$store.property in a Vue component, you need to provide the created store to the Vue instance. Vuex provides a mechanism to "inject" the store from the root component to all child components as a store option. //main.js import store from './store' new Vue({ el: '#app', store, //root component injection store }) //index.vue getData() { return { userId: this.$store.state.user.userId, ...... } } If you want to use store in a js file, you must first import store from '@/store' and then use store.xxx, because this.$store cannot be printed in js. // src/test.js fileimport store from './store/'; console.log(store) console.log(this) // undefined console.log(this.$store) // will report an error this.$store and $store$store is mounted on the Vue instance (i.e. Vue.prototype), and the component is actually a Vue instance. You can use this in the component to access the properties on the prototype. <template> has the context of the component instance, which can be accessed directly through {{$store.state.XXX }}, which is equivalent to this.$store.state.XXX in the script Just think of $store as a variable returned in data. You need to add this when using it in the script below, but not in the template above. The above is my personal experience. I hope it can give you a reference. I also hope that you will support 123WORDPRESS.COM. You may also be interested in:
|
<<: Analysis of the principle and usage of MySQL custom functions
>>: Detailed explanation of the implementation process of Nginx log timing splitting in CentOS 7
1. Install dependency packages yum -y install gcc...
MySQL regular sorting, custom sorting, and sortin...
1. DNS server concept Communication on the Intern...
This article shares the specific code of Vue.js f...
By default, the width and height of the cell are ...
1. Command Introduction The userdel (user delete)...
In a complex table structure, some cells span mul...
This article example shares the specific code of ...
When Docker starts a container, it specifies the ...
<!DOCTYPE HEML PUBLIC> <html> <hea...
Web design, according to personal preferences and ...
In more and more websites, the use of XHTML is rep...
The div element is used to provide structure and b...
Problem Description When we are working on a proj...
Table of contents 1. Download the tomcat code 2. ...