且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

从Rest API填充Vue模板组件中的表

更新时间:2022-04-11 04:45:25

编辑后,您得到了正确的错误,此错误的范围已在axios.get内部更改,您需要进行以下更改:

as you have edited, you have got the correct error, scope of this has changed inside axios.get, you need to make following changes:

methods: {
  getCourses: function () {
    var self = this
    const url = 'https://server/CoursesWebApi/api/courses/'
    axios.get(url, {
      dataType: 'json',
      headers: {
        'Accept': 'application/json',
        'Content-Type': 'application/json'
      },
      mode: 'no-cors',
      credentials: 'include'
    })
    .then(function (response) {
      console.log(JSON.stringify(response.data))
      self.courses = response.data
    })
    .catch(function (error) {
      console.log(error)
    })
  }
}