Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to get variables in vue data using store

2025-01-18 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/01 Report--

This article mainly explains "how to get variables in vue data using store", the content of the explanation is simple and clear, easy to learn and understand, please follow the editor's ideas slowly in-depth, together to study and learn "how to get variables in vue data using store"!

Data gets variables that use store

We want to use the global variable defined in store, which is always empty or undefined, but it is actually very simple:

For example, if we need to use the user id when we call the backend interface, we first need to obtain the userId defined in store.

The methods are as follows:

1. This is the attribute defined in store (let's get the user id as an example)

two。 Get it directly from the computed of the current page you want to use

3. Then you can use it directly through this.userid. For example, after I get it, I print it in created to verify it. The result is as follows:

Unable to get variable problem in $store

The requirement is to send the login user's ID to the back end, which is written as this.$store.user.userID.

As a result, the backend did not receive it, and it turned out that a state was missing.

It was normal when it was changed to this.$store.state.user.userID.

Thank you for your reading, the above is the content of "how to get variables in vue data using store". After the study of this article, I believe you have a deeper understanding of how to get variables in store in vue data, and the specific use needs to be verified in practice. Here is, the editor will push for you more related knowledge points of the article, welcome to follow!

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: 253

*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.

Share To

Development