json的定义:
JSON(JavaScript Object Notation) 是一种轻量级的数据交换格式。
JSON 是 JS 对象的字符串表示法,它使用文本表示一个 JS 对象的信息,本质是一个字符串。
1.require-运行时加载
test.json文件
{
"testData": "hello world",
"testArray": [1,2,3,4,5,6],
"testObj": {
"name": "tom",
"age": 18
}
}
// require引用时,放src和放statci都可以,建议放static
const testJson = require('../../static/json/test.json');
console.log('testData', testData);
2.import-编译时输出接口
import testImportJson from '../../static/json/test.json'
console.log('testData', testData);
3. 通过http请求获取
this.$http.get('http://localhost:8080/static/json/test.json').then(res => {
console.log('testData', res.data);
});