2018-09-25

axios
<div id="app">
<router-link to='/home'>这是首页</router-link>
<router-link to='/user'>这是详情页</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 type="text/javascript">
var Home={
template:<h1>这是首页内容</h1>
}
var Detail={
template:`
<div>
<h1>这是详情页内容</h1>
<table border=1 cellspacing=0>
<thead>
<tr>
<th>编号</th>
<th>品名</th>
<th>单价</th>
<th>数量</th>
<th>小计</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({
                    method:'get',
                    url:'fruit.json'
                }).then(function(resp){
                    console.log(resp.data)
                    self.fruList=resp.data
                }).catch(function(err){
                    
                })
            }
        }
        const routes=[
            {path:'/',componpent:Home},
            {path:'/home',component:Home},
            {path:'/detail',component:Detail}
        ]
        const router=new VueRouter({
            routes:routes
        })
        new Vue({
            el:'#app',
            router:router
        })
    </script>
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容

  • 非父组件 <first></first> 组件嵌套 <router-link to='/home'>首页</ro...
    轩呓阅读 144评论 0 0
  • 1.vue-router相当于vue的第三方数据库。 用处1.通过不同的url访问不同的页面,实现spa(sing...
    没人要的野狗罢了阅读 209评论 0 0
  • 1.简单的路由嵌套例子 需要注意在要嵌套的路由最后添加children,写成数组对象形式添加相对应的路径,把需要嵌...
    LYH2312阅读 192评论 0 0
  • 轻轻听 不要言语 万籁静待的时分 香消爱恋 似幻似真 过往有几分真情 人世尽 单影炉壁 你怎知凋零的颜色 恍恍惚惚...
    乌合旮旯吉阅读 181评论 0 0