【发布时间】:2021-07-10 12:11:04
【问题描述】:
我是 Vue.js 的初学者。
我正在尝试对我的 /src/component/data.js 进行 axios 调用
文件如下所示:
const myData = () => {
return new Promise((resolve, reject) => {
resolve(data());
});
};
const data = () => {
return [
{
name: "A"
},
{
name: "B"
}
];
};
export { myData };
当我试图访问HelloWorld.vue 上的数据时:
<script>
import axios from "axios";
import { mydata } from "./data";
export default {
...
async mounted() {
const response = await axios.get(mydata);
console.log(response);
}
};
</script>
错误显示
TypeError: Cannot read property 'protocol' of undefined
我想要的结果是
[
{
name: "A"
},
{
name: "B"
}
]
代码沙盒:
https://codesandbox.io/s/eloquent-haibt-1bnib?file=/src/components/HelloWorld.vue:1790-2040
不修改data.js如何解决?
【问题讨论】:
标签: javascript vue.js axios