亚洲乱码中文字幕综合,中国熟女仑乱hd,亚洲精品乱拍国产一区二区三区,一本大道卡一卡二卡三乱码全集资源,又粗又黄又硬又爽的免费视频

vue請(qǐng)求本地自己編寫的json文件的方法

 更新時(shí)間:2019年04月25日 15:44:33   作者:遇你溫柔如初  
這篇文章主要介紹了vue請(qǐng)求本地自己編寫的json文件,非常不錯(cuò),具有一定的參考借鑒價(jià)值,需要的朋友可以參考下

1.第一步,這是目錄結(jié)構(gòu)

2.接下來(lái)是build/webpack.dev.conf.js文件需要配置的內(nèi)容

代碼:

//vue配置請(qǐng)求本地json數(shù)據(jù)
const express = require('express')
const app = express()
const appData = require('../static/major_info.json')//加載本地json文件
const majorlist = appData.contents;//獲取本地對(duì)應(yīng)數(shù)據(jù)
const apiRoutes = express.Router()
app.use('/api',apiRoutes)

代碼:

before (app) {
  app.get('/api/majorlist',(req, res) => {
    res.json({
      erron:0,
      data: majorlist
    })//接口返回json數(shù)據(jù),上面配置的數(shù)據(jù)majorlist就賦值給data請(qǐng)求后調(diào)用
   })
 }

3.接下來(lái)就是vue文件的請(qǐng)求寫法:

代碼:

created(){
  let _this = this;
  this.$http.get("/api/majorlist").then(function(response){
    // console.log(response.data.data);
    let data = response.data.data;
    for(let i = 0; i < data.length; i++){
      if(this.majorIndex == data[i].type){
        this.dataList = data[i];
      }
    }
  })
  .catch(function(error){
    console.log("出錯(cuò)嘍:"+error);
  });
 }

 4.這是我的json文件數(shù)據(jù)格式

總結(jié)

以上所述是小編給大家介紹的vue請(qǐng)求本地自己編寫的json文件的方法,希望對(duì)大家有所幫助,如果大家有任何疑問(wèn)歡迎給我留言,小編會(huì)及時(shí)回復(fù)大家的!

相關(guān)文章

最新評(píng)論