vuex

Do Vue watched properties cache just like the computed properties?

风格不统一 提交于 2019-12-11 00:55:06
问题 In the Vue docs it is mentioned that computed properties are smartly cached as opposed to using regular methods: In comparison, a method invocation will always run the function whenever a re-render happens. Why do we need caching? Imagine we have an expensive computed property... My question is : Do watched properties also having caching like computed properties? (including Vuex watching, eg. using vm.$store.watch... ) 回答1: Behaviour of watchers will be same as behaviour of computed as

The context of this not provided to the modules exporting

為{幸葍}努か 提交于 2019-12-11 00:50:09
问题 I'm displeased with the formulation of the question. Feel encouraged to suggest an improvement. Also, please keep in mind that due to ignoyance (ignorance leading to annoyance), I might have flawed diagnostics of hte issue. Sorry about that. In this answer it's suggested to use this.$store.xxx and it fails in my code because this is undefined. I strongly suspect something stupid being done by the author of the code (that would be me), so I'll present the schematics of my component layout. The

Update state with Apollo Client

大城市里の小女人 提交于 2019-12-10 22:36:34
问题 I am trying to use ApolloClient with Vuex but I stumbled upon a problem I can't resolve. I call ApolloClient.query() function inside a vuex action but it seems like the function always returns a resolved promise from the first action call. So, after the function got fired once, no request goes to the server and I get the same result as when I load the page (although the actual data in database gets changes). If I take a look at Apollo Dev Tools, there's also no changes to the Apollo state

Vue.js/vuex ajax update components with ajax state

限于喜欢 提交于 2019-12-10 19:27:09
问题 I'm using vue webpack template with vuex and I'm basically having issues with components not updating with the state. I have a store const state = { userData: {}, } In my app I have a method methods: { addUserData: function() { const that = this; axios.get('URL').then(function (response) { let obj = response.data; that.$store.commit('addUserData', {obj}); }); }, which I call when it's mounted mounted () { this.addUserData(); }, Which is updated with a mutation const mutations = { addUserData

Ensure that Vuex state is loaded before render component

限于喜欢 提交于 2019-12-10 18:41:05
问题 I have a add-user.vue component. It is my template for adding a new user and editing a existing user. So on page load I check if route has a id , if so I load a user from a state array to edit it. My issue is that user is undefined because the state array users is empty. How can I ensure that my user object isn't undefined. It does load sometimes but on refresh it doesn't. I thought I had it covered but nope. This is my setup. What am I missing here? Store state: { users: [] }, getters: {

How can I reload a vue component?

对着背影说爱祢 提交于 2019-12-10 18:35:59
问题 I know the solution is update the prop data like this : this.selectedContinent = "" But I want to use another solution After I read some reference, the solution is : this.$forceUpdate() I try it, but it does not work Demo and full code like this : https://jsfiddle.net/Lgxrcc5p/13/ You can click button test to try it I need a solution other than update the property data 回答1: You have to assign a key to your component. When you want to re-render a component, you just update the key. More info

Is there a way to remove a directory from a dynamic URL using Vue-Router?

大城市里の小女人 提交于 2019-12-10 18:27:05
问题 I've build a vue.js web app for an insurance brokerage where every agent has their own website that is generated from their profiles. This is what the link looks like in my vue-router index file" { path: '/agents/:id', name: 'AgentSite', component: AgentSite }, Everything works great EXCEPT that the urls are getting too long to fit on some business cards. I would like to change the URLs to be like this: { path: '/:id', name: 'AgentSite', component: AgentSite }, However, then every other bit

Pagination in Vuex Store

徘徊边缘 提交于 2019-12-10 18:18:53
问题 I have cloned this awesome shopping cart repo from https://github.com/vueschool/learn-vuex, and i get data like this: ProductList.vue <template> <div> <ul> <li v-for="product in products"> - {{product.name}} - {{product.price}} </li> </ul> </div> </template> <script> methods: { ...mapActions({ fetchProducts: 'products/fetchProducts' }) } </script> export default new Vuex.Store({ state: { products: {}, }, actions: { fetchProducts({commit},data) { axios.get(`api/product`).then((response) => {

No Vuex store detected in Vue Dev Tools

此生再无相见时 提交于 2019-12-10 17:53:01
问题 For very specific reasons, I have set the vue dev tools to true in production. Vue.config.devtools = true Am using the following versions: "vue": "^2.5.2" "vuex": "^3.0.1" "vuetify": "^1.0.0" While I can see the components and events, the Vuex store is not detected. I have tried downgrading the vuex version to 2.3.1 and 2.4.x, but it did not help. Here's the link I referred to - https://github.com/vuejs/vue-devtools/issues/405 Note - The store works well, its just that I am not able to view

How to solve Uncaught ReferenceError: bus is not defined? (vue.js 2)

空扰寡人 提交于 2019-12-10 15:52:31
问题 I follow this tutorial : https://vuejs.org/v2/guide/components.html#Non-Parent-Child-Communication It to passing data from a component to other component See my case below. I try like that My view is like this : <div class="row"> <div class="col-md-3"> <search-filter-view ...></search-filter-view> </div> <div class="col-md-9"> <search-result-view ...></search-result-view> </div> </div> My search-filter-view component is like this : <script> export default{ props:[...], data(){ return{ ... } }