2018-09-25

axios:

vue ajax 前端頁面和后臺(tái)數(shù)據(jù)進(jìn)行交互 json
vue 庫
<!DOCTYPE html>

<html lang="en">

<head>

    <meta charset="UTF-8">

    <title>Document</title>

</head>

<body>

  <div id='app'>

      <router-link to='/home'>首頁</router-link>

      <router-link to='/detail'>詳情頁</router-link>

      <router-view></router-view>

  </div>

    <script src='js/vue.js'></script>

    <script src='js/vue-router.js'></script>

    <script src='js/axios.js'></script>

    <script>

       var Home={

           template:`

             <h1>這是首頁內(nèi)容</h1>

      }

        var Detail={

          template:`

            <div>

            <h1>這是詳情頁內(nèi)容</h1>

            <table border=1 cellspacing=0>

                  <thead>

                      <tr>

                        <th>編號</th>

                        <th>品名</th>

                        <th>單價(jià)</th>

                        <th>數(shù)量</th>

                        <th>小計(jì)</th>

                      </tr>

                  </thead>

                  <tbody>

                      <tr v-for="value in fruList">

                          <td>{{value.num}}</td>

                          <td>{{value.pname}}</td>

                          <td>{{value.price}}</td>

                          <td>{{value.count}}</td>

                          <td>{{value.sub}}</td>

                      </tr>

                </tbody>

            </table>

            </div>

            `,

          data:function(){

                return{

                    fruList:null

                }

        },

        mounted:function(){

            var self=this;

            axios({
          //發(fā)送數(shù)據(jù)的方式

                method:'get',

                url:'fruit.json'

              //請求成功

            }).then(function(resp)

                console.log(resp.data)

                self.fruList=resp.data

          請求失敗

            }).catch(function(err){

            })

        }   

      }

3.配置路由

        const routes=[

            {path:'/',component:Home},

            {path:'/home',component:Home},

            {path:'/detail',component:Detail}

        ]
  1.      const router=new VueRouter({
    
             routes:routes
    
         })
    
         5.
    
       new Vue({
    
           el:"#app",
    
           router:router
    
       })
    
     </script>
    
       </body>
    
         </html>
    

下載:

      npm install axios

    訪問頁面:

      網(wǎng)址:127.0.0.1:8080

    安裝http-server: 

    npm install http-server -g
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請結(jié)合常識(shí)與多方信息審慎甄別。
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡書系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

  • 1.vue-router相當(dāng)于vue的第三方數(shù)據(jù)庫。 用處1.通過不同的url訪問不同的頁面,實(shí)現(xiàn)spa(sing...
    沒人要的野狗罷了閱讀 272評論 0 0
  • 相關(guān)概念 混合開發(fā)和前后端分離 混合開發(fā)(服務(wù)器端渲染) 前后端分離后端提供接口,前端開發(fā)界面效果(專注于用戶的交...
    他愛在黑暗中漫游閱讀 3,022評論 4 45
  • vue是什么? vue是構(gòu)建數(shù)據(jù)驅(qū)動(dòng)的web界面的漸進(jìn)式框架。Vue.js 的目標(biāo)是通過盡可能簡單的 API 實(shí)現(xiàn)...
    九四年的風(fēng)閱讀 8,818評論 2 131
  • # 傳智播客vue 學(xué)習(xí)## 1. 什么是 Vue.js* Vue 開發(fā)手機(jī) APP 需要借助于 Weex* Vu...
    再見天才閱讀 3,800評論 0 6
  • 非父組件 <first></first> 組件嵌套 <router-link to='/home'>首頁</ro...
    軒囈閱讀 161評論 0 0

友情鏈接更多精彩內(nèi)容