vue项目导入本地json文件的2种方法
一、通过网络请求导入
步骤:
1.找到vue项目目录下的build/webpack.dev.conf.js文件
2.
在此注册json文件3.
找到devServer方法,在里面 声明访问的方法和路径4.在页面钩子函数触发时,调用
created() {
this.$http.get('/api/customs_cut_mode').then((response) => {
response = response.body;
if (response.errno == ERR_OK||response.errno ==0) {
this.customs_cut_mode= response.data;
}
});
}
二、通过ES6导入本地json
1.将json数据放入指定目录。
2.在页面引入
import customs_cut_mode from '../../common/Alljson/customs_cut_mode.json'
3.页面使用
mounted() {
this.customs_cut_mode= customs_cut_mode
// console.log( this.customs_cut_mode)
},
网友评论