VUE组件|vue 读取本地代码(static目录下的json文件,并加载显示页面上)

先上效果图:
VUE组件|vue 读取本地代码(static目录下的json文件,并加载显示页面上)
文章图片

从效果图可以看出是点击:button打开json文件按钮的方法:
html:
调用的方法是:
open_changeFile(){
}
正确写法:
前提vue里面引入了axios了:
引入方法:
import axios from 'axios'

// 打开本地json文件,预览页面 open_changeFile(){ //用axios的方法引入地址 this.$axios.get('http://tcc:1000/static/fileJson/save.json').then((res) => { console.log(res); if(res.status == "200"){ // 赋值显示在页面 this.fileData = https://www.it610.com/article/JSON.parse(JSON.stringify(res.data)); console.log("this.fileData:",this.fileData); this.connectors = this.fileData.connectors; this.nodes = this.fileData.nodes; } }) },

【VUE组件|vue 读取本地代码(static目录下的json文件,并加载显示页面上)】

    推荐阅读