javascript - 无法使用 Vue-router 加载配置文件数据
问题描述
已解决: url: ('/api' +this.profilepath),
在我的项目中添加了 Vue-router,无法再加载配置文件数据。
---- 编辑---- this.$router.currentRoute.fullPath,不是给我完整路径。/api/ 不见了……
这是侧边栏组件:
<li class="nav-item">
<router-link :to="{ name: 'profile' , params:{id: this.profileId}}"
class="nav-link"
:key="$route.fullPath"
>Profile</router-link>
我将配置文件 ID 传递给我的配置文件组件。
侧边栏组件通过 props 获取配置文件 ID:
props: ['profileid'],
Profile组件正在生成axios“GET”路径:
data() {
return {
status: 'Loading ...',
profilepath: this.$router.currentRoute.fullPath,
profile: {
},
}
},
我在配置文件组件中“获取”配置文件数据的方法:
methods: {
loadProfile(){
console.log(this.profilepath);
this.status = 'Loading ....';
axios({
url: this.profilepath,
method: 'get'
})
.then(response => {
this.profile = response.data.profile;
this.status = ('data received ....' );
console.log('data received ....' +this.profile);
this.status = 'Data loaded, succesfully!';
})
这工作正常,现在只从我的 Laravel 后端接收一个空数组。我的请求 URL 正在传递配置文件 ID:http://192.168.10.101:8000/api/profile/1
问)在使用 Vue-router 链接时,我应该为 axios 添加一些额外的东西吗?
Error: in render: "TypeError: _vm.profile is undefined"
我从子组件 Userinfo 中找到了这个,它应该通过props: ['profile']
- 更新 - -
当我在方法内部进行故障排除时loadProfile()
:
console.log(this.profilepath);
它返回:/profile/1
这是错误的!
问题是缺少'/api/',这就是为什么,我只收到一个空数组。
profilepath:this.$router.currentRoute.fullPath,不包括/api/。
解决方案
推荐阅读
- typescript - 简化 Typescript 装饰器功能
- javascript - 如何获得添加单元格的总和
- c++ - 在 GetOpenFileName() 对话框之后,cv::imread() 将无法处理 .jp2 文件
- android - 如何使用 6 个片段和 1 个 Activity 插入不同的大量数据
- java - 如何在获取 Java 的同时从日食氧气更新为光子?
- mysql - 选择日期小于指定日期的每组的最新行
- python - 在列表列表中搜索列表的快速方法
- c# - 如何验证/检查图像是否已存在于数据库中?
- python - Python:CSV - 如果其他列足够大,则打印列的值
- java - 如何将不同的用户重定向到不同的活动?