<template>
<div class="dd"></div>
</template>
<script>
import apifrom '../api.json'
let dataList=api
export default{
data(){
return {
}
},
mounted () {
this.getGoodsList()
},
methods: {
async getGoodsList (data) {
const res=await dataList(data)
console.log(res);
}
}
}
</script>
<style>
</style>
想使用json文件异步获取数据,请问各位专家 应该怎样写获取到数据
<template>
<div class="dd"></div>
</template>
<script>
export default{
data(){
return {
}
},
mounted () {
this.getGoodsList()
},
methods: {
async getGoodsList (data) {
const res=await this.$axios.get('../api,json')
console.log(res);
}
}
}
</script>
<style>
</style>
如有帮助,麻烦点个【采纳此答案】
你是要拿到api.json 这个文件的json数据吗 本地的引入的就直接有了 不需要获取;
是复制错了吗,api from中间空格没了