美文网首页
vue项目导入本地json文件的方法

vue项目导入本地json文件的方法

作者: 风雨兼程620 | 来源:发表于2019-04-01 14:11 被阅读0次

    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)

        },

    相关文章

      网友评论

          本文标题:vue项目导入本地json文件的方法

          本文链接:https://www.haomeiwen.com/subject/grombqtx.html