在app.vue和main.js中引入axios(import axios from 'axios')

基本代码:

  axios.get('/axios.json')

    .then(function(response){

      console.log(response.data.name);

    })

    .catch(function(error){

      console.log(error)

    })

   (注意:文件只能放在static文件夹中,或者是和index.html同级,并且用根路径的方式获取,否则会报错404.)

 

渲染json到页面:

 

Vue中引入组件步骤:

1.创建component文件夹并创建Hello.vue组件

2.在app.vue中引入 并在template中引入组件