简体   繁体   English

来自Ajax请求的Vue.JS路由器链接参数

[英]Vue.JS router-link params from ajax request

Im trying to create a router-link with vue and when I try to pass a parameter I receive from an AJAX request using axios. 我试图用vue创建一个路由器链接,当我尝试传递参数时,我使用axios从AJAX请求中接收到了参数。 But at the moment I load the page i get the notice the parameter is missing and it shows up as undefined. 但是在我加载页面的那一刻,我注意到该参数丢失了,并且显示为未定义。 How do i get around this? 我该如何解决?

<tr v-for="obj in fetched">
    <td v-text="obj.isocode"></td>
    <td v-text="obj.name"></td>
    <td><router-link :to="{ name: 'str-route-masterdata-country-edit', params: { id: obj.id }}">Edit</router-link></td>
</tr>

export default {
        name: "starlight-masterdata-country-index",
        components: {StarlightTable},
        data: function() {
            return {fetched: []}
        },
        mounted: function () {

            let vm = this;

            Axios.get('http://127.0.0.1:5000/masterdata/countries',
                {crossDomain: true}
            )
                .then(function (response) {
                    // handle success
                    vm.fetched = response.data;
                })
                .catch(function (error) {
                    // handle error
                    //TODO: Add flash message to screen to show the api request failed
                    window.console.log(error);
                });
        },

    }

Error message: 错误信息:

vue-router.esm.js?8c4f:16 [vue-router] missing param for named route "str-route-masterdata-country-edit": Expected "id" to be defined

Already solved. 已经解决了。 Used the wrong property. 使用了错误的属性。 Needed to be uuid instead of id.. 需要是uuid而不是id。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM