0

I have the following setup for my vue application

var store = {
    ...
    state: {
        currentCustomer:{},
    },
};

current customer has a property that is an object called payment method

app:

 var app= new Vue({
el:'#application',
 data: {
  sharedState: store.state
  }
});

and a couple of components:

Vue.component('user_search', {
    template: '#user_search-template',
    data() {
        return {
            sharedState: store.state
        }
    },
    methods: {
        getCustomerData: function () {
                            this.sharedState.currentCustomer(c);
        }

    mounted: function () {
        ...         
    }
});

and

Vue.component('paymentdetails',{
    template: '#payment_details_template',
    data(){
        return{

            sharedState: store.state
        }
    },
    mounted:function(){
            ...

    }});

The issue is like this. The payment method component does not bind to the payment details object that is nested inside the current customer object

any suggestions?

2
  • See Change Detection Caveats. Commented Dec 11, 2019 at 12:21
  • make a computed property on the nested proerty. Alternatively force a rerender by changing the key on the component, it will then get the updated data. Commented Dec 11, 2019 at 12:53

1 Answer 1

1

Yeah, I think what you are looking for is a computed property for accessing the data.

Vue.component('paymentdetails',{
    template: '#payment_details_template',
    computed{
        sharedState() {
            return store.state
        }
    },
    mounted:function(){
            ...

    }});

Maybe give that a try and see how it works.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.