vue中的axios

ajax:前端頁(yè)面和后臺(tái)數(shù)據(jù)做交互

把后臺(tái)數(shù)據(jù)輸出到前臺(tái)

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
</head>
<body>
<div id="app">
    <router-link to="/home">首頁(yè)</router-link>
    <router-link to="/user">用戶頁(yè)</router-link>
    <router-view></router-view>
</div>
<script src="dist/vue.js"></script>
<script src="dist/vue-router.js"></script>
<script src="dist/axios.js"></script>
<script>
    var home={
        template:`
            <h1>我是首頁(yè)</h1>
        `
    }
    var user={
        template:`
            <div>
                <h1>我是用戶頁(yè)</h1>
                <table border=1 cellspacing=0>
                   <thead>
                       <tr>
                         <th>編號(hào)</th>
                         <th>品名</th>
                         <th>單價(jià)</th>
                         <th>數(shù)量</th>
                         <th>小計(jì)</th>
                       </tr>
                   </thead>
                   <tbody>
                      <tr v-for="value in list">
                         <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{
                list:null
            }
        },
        mounted:function(){
            var rsel=this
            axios({
                method:'get',
                url:'fruit.json'
            }).then(function(resp){
                console.log(resp.data)
                rsel.list=resp.data
            }).catch(function(err){
                console.log(err)
            })
        }
    }
    const routes=[
        {path:'/',component:home},
        {path:'/home',component:home},
        {path:'/user',component:user}
    ]
    const router=new VueRouter({
        routes:routes
    })
    new Vue({
        el:'#app',
        router:router
    })
</script>
</body>
</html>
[
  {
    "num":1,
    "pname":"apple",
    "price":3,
    "count":2,
    "sub":6
  },
  {
    "num":2,
    "pname":"pear",
    "price":4,
    "count":3,
    "sub":12
  },
  {
    "num":3,
    "pname":"banana",
    "price":5,
    "count":4,
    "sub":20
  }
]
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請(qǐng)結(jié)合常識(shí)與多方信息審慎甄別。
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡(jiǎn)書系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。

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

  • Android 自定義View的各種姿勢(shì)1 Activity的顯示之ViewRootImpl詳解 Activity...
    passiontim閱讀 179,147評(píng)論 25 708
  • 用兩張圖告訴你,為什么你的 App 會(huì)卡頓? - Android - 掘金 Cover 有什么料? 從這篇文章中你...
    hw1212閱讀 14,039評(píng)論 2 59
  • 1.axios(vue中的ajax)
    信不由衷閱讀 472評(píng)論 0 0
  • 首先配置通用設(shè)置 接著 配置攔截器 最后去配置get方法和post方法 最后 掛載到Vue對(duì)象上再main.js中...
    ErrorCode233閱讀 4,610評(píng)論 0 9
  • 說(shuō)明:除了提供var的變量聲明方法,還提供了將變量綁定到所有的任意作用域中(通常是{..}內(nèi)部)換句話說(shuō):let,...
    LingJJ1100的筆記閱讀 853評(píng)論 0 0

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