关于 vuejs2:\\”TypeError: Cannot read property \\
尝试使用 axios 从 api 访问获取请求时,我从 Vue 收到这个奇怪的错误,
我收到 "TypeError: Cannot read property \\'get\\' of undefined"
1
2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 |
<template>
{{ msg }} <p>Welcome to your new single-page application, built with Vue.js.</p> </template> var Vue = require('vue'); // import axios from"axios"; window.axios=require('axios'); export default { name: 'Home', props: { msg: String }, component: { }, mounted: function () { alert('Hi '); this.axios.get('https://api.github.com/users') .then(value => { alert(value); }); } }; <!-- Add"scoped" attribute to limit CSS to this component only --> <style scoped> </style> |
相关讨论
1
|
import axios from 'axios';
|
更有效的方法是在
1
|
Vue.prototype.$http = axios
|
并在任何你想要的地方使用它