vue.js - 我想在axios get方法中将id调用到兄弟组件中,并在vue客户端表中显示输出数据
问题描述
created () {
let self = this;
// after this point, `self` will reference the Vue instance even in callbacks
this.$root.$on('eventing', tableDataId => {
axios.get('http://192.168.2.35:8000/api/v1/post_bi' + '/' + tableDataId)
.then((response) => {
// setting `self` to `this` here doesn't make sense because `this`
// is not refering to the Vue instance in this callback
self.tableData = response.data;
console.log(self.tableData)
})
.catch((error) => {
console.log(error)
})
})
我写了这段代码,但是表数据的输出没有显示在 v 客户端表中。
解决方案
尝试这个
created () {
axios.get('http://192.168.2.35:8000/api/v1/post_bi/'+ this.tableDataId)
.then((response) => {
this.tableData = response.data;
})
.catch((error) => {
console.log(error)
})
})
假设您已经像这样在组件中声明了 tableData 和 tableDataId
data() {
return {
tableData: '',
tableDataId: '',
}
}
推荐阅读
- java - Android - CardView 变成菱形,因为半径太大
- highcharts - 带有fillColor的Highcharts区域图根据区域颜色改变颜色?
- ffmpeg - FFmpeg amix + 音量过滤器创建饱和输出?
- postgresql - 与 Airflow 元数据数据库的大量连接
- javascript - 试图让这个切换音频播放器工作
- javascript - 可能并不总是存在的查询对象字段
- linux - Nginx反向代理 - 相同的服务器名称不同的端口
- sql - 我正在尝试计算 SQL 中的延时,但它以“微秒”为单位给出了结果
- javascript - 如何解决多个嵌套 forEach 循环中的承诺?
- javascript - 为什么不给递归加1?