配置vuejs加載模擬數據

【我的筆記,非技術博客】javascript

1.使用前確保安裝axios插件,vuejs官方推薦,固然使用其餘插件也能夠vue

二、配置dev-server.jsjava

var router = express.Router();
var bookData =  require('./../mock/book.json');//加載json數據
router.get("/book",function (req,res,next) {
  res.json(bookData);
});
app.use(router);

  

三、導入axiosios

四、訪問數據express

import NavHeader from "./../components/header/header.vue"
  import NavFooter from "./../components/footer/footer.vue"
  import NavBread from  "./../components/navBread/navBread.vue"
  import axios from 'axios'
  export default{
      data(){
         return {
             bookList:[]
         }
      },
    components:{
        NavHeader,
        NavFooter,
        NavBread
    },
    mounted:function () {
      this.getGoodsList();
    },
    methods:{
          getGoodsList(){
              axios.get("/book").then((result)=>{
                  var res = result.data;
                  this.bookList = res.result;
              })
          }
    }
  }

五、使用數據json

<div>
      <ul>
        <li v-for="(item,index) in bookList">
          <img v-bind:src="'/static/images/'+item.bookImg"/>
          <div>{{item.bookName}}</div>
          <div>{{item.bookAuthor}}</div>
        </li>
      </ul>
    </div>
相關文章
相關標籤/搜索