Ustinian_ 2022-05-03 12:41 采纳率: 83.3%
浏览 668

vue中使用axios返回值给data赋值

问题遇到的现象和发生背景
data() {
            return {
                chartInstance: null,
                allData: null, // 服务器返回的数据
                       }
           },
mounted() {
                this.getData()
                },
methods: {
                getData() {
                                  let vue = this
                                   // http://127.0.0.1:80000/seller
                                    const ret = this.$http.get('seller/',{
                                             params:{"table":"civil_2022"}
                                     })
                                   .then((response)=>{
                                     // console.log(response.data)
                                            this.allData = response.data
                                       })
                                    .catch(function(error) {
                                                  console.log(error);
                                      });
                                    console.log(this)
                                   }
               }

最后一行打印的结果 能看到allData的值
但是console.log(this.allData)的时候结果却为null

问题相关代码,请勿粘贴截图
运行结果及报错内容
我的解答思路和尝试过的方法
我想要达到的结果
  • 写回答

2条回答 默认 最新

  • 你好!机器人 2022-05-03 13:40
    关注
    
    data() {
                return {
                    chartInstance: null,
                    allData: null, // 服务器返回的数据
                           }
               },
    mounted() {
                    this.getData()
                    },
    methods: {
                    getData() {
                                     this.$http.get('seller/',{
                                                 params:{"table":"civil_2022"}
                                         })
                                       .then((response)=>{
                                                this.allData = response.data
                                        console.log(this.allDat)
                                           })
                                        .catch(function(error) {
                                                      console.log(error);
                                          });
                                       }
                   }
    
    评论

报告相同问题?

问题事件

  • 创建了问题 5月3日

悬赏问题

  • ¥15 如何在maya程序中利用python编写领子和褶裥的模型的方法
  • ¥15 Linux权限管理相关操作(求解答)
  • ¥15 Bug traq 数据包 大概什么价
  • ¥15 在anaconda上pytorch和paddle paddle下载报错
  • ¥25 自动填写QQ腾讯文档收集表
  • ¥15 DbVisualizer Pro 12.0.7 sql commander光标错位 显示位置与实际不符
  • ¥15 求一份STM32F10X的I2S外设库
  • ¥15 android 打包报错
  • ¥15 关于stm32的问题
  • ¥15 ncode振动疲劳分析中,noisefloor如何影响PSD函数?