Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/vue.js/6.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 获取后未更新Vue.js组件数据_Javascript_Vue.js_Vuejs2 - Fatal编程技术网

Javascript 获取后未更新Vue.js组件数据

Javascript 获取后未更新Vue.js组件数据,javascript,vue.js,vuejs2,Javascript,Vue.js,Vuejs2,我有一个包含默认对象的组件,在创建时会得到一个填充的对象。当尝试将this.profile绑定到新对象时,它似乎在方法中获得了正确的数据,但更改不会被推回到this.profile的其他用途。是否有办法强制脚本的其余部分接受此更改 export default { data() { return { profile: { firstName: 'Seller First Name', surname: 'Seller Sur

我有一个包含默认对象的组件,在创建时会得到一个填充的对象。当尝试将this.profile绑定到新对象时,它似乎在方法中获得了正确的数据,但更改不会被推回到this.profile的其他用途。是否有办法强制脚本的其余部分接受此更改

export default {
data() {
    return {
        profile: {
            firstName: 'Seller First Name',
            surname: 'Seller Surname',
            username: '',
            biography: 'Seller biography.',
            phoneNumber: 'Seller Phone Number',
            emailAddress: 'Seller Email',
            profilePhotoUrl: '',
            testimonials: []
        }
    };
},

components: {
    ProfileSummary,
    Biography,
    TestimonialList,
    PaymentsenseCompany
},

created() {
    console.log('created');
    this.getProfile(this.$route.params.sellerUsername);
},

methods: {
    getProfile(sellerUsername) {
        axios.get('http://fieldsellerprofileapi.azurewebsites.net/api/fieldseller/' + sellerUsername)
        .then(function(response) {
            this.profile = Object.assign({}, response.data);
            Vue.nextTick(() => {
                console.log('after', this);
            });
        }.bind(this))
        .catch(e => {
            console.log(e);
            // location.replace('/404');
        });
    }
},

我不确定,但试试这个:

getProfile(sellerUsername) {
  axios
    .get('http://fieldsellerprofileapi.azurewebsites.net/api/fieldseller/' + sellerUsername)
    .then(r => this.profile = r.data)
    .catch(e => console.log(e))
}

因此,问题并不是这些值没有被更新。它们保存得很好,我只是试图在一个子组件中访问它们,由于某种原因,该组件没有被父组件更新。这些变化并没有传播到孩子们身上。。。如果你有同样的问题,这可能是有用的

谢谢