简体   繁体   中英

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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