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

vue项目导入本地json文件的方法,第1张

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

一、通过网络请求导入

步骤:

1.找到vue项目目录下的build/webpack.dev.conf.js文件

2.

3.

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)

    },

1:在static文件夹底下新建json文件,( 本地JSON文件一定要需放在static文件夹之下。)

访问服务器文件,应该把 json文件放在最外层的static文件夹,这个文件夹是vue-cli内置服务器向外暴露的静态文件夹。

2:写一个axios


欢迎分享,转载请注明来源:内存溢出

原文地址: https://outofmemory.cn/bake/11740444.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2023-05-18
下一篇 2023-05-18

发表评论

登录后才能评论

评论列表(0条)

保存