Vue完成页面切换中加载数据

created() {
            // 拿到路由传递来的car主键
            let pk = this.$route.query.pk || this.$route.params.pk;
            // 主键不存在,就直接结束方法
            if (!pk) return false;
            // 主键存在才请求后台
            //axios如同js的ajax,不过使用axios需要在main.js中先导入
            this.$axios({
                url: this.$settings.base_url + `/car/${pk}/`,
                //成功的时候使用then函数后去成功数据
            }).then(response => {
                this.car = response.data
                //错误的时候使用catch函数后去错误信息
            }).catch(error => {
                console.log(error.response)
            })

猜你喜欢

转载自www.cnblogs.com/mqhpy/p/12085261.html