• 058——VUE中vue-router之实例操作新闻列表单页面应用与路由别名的使用


    <!DOCTYPE html>
    <html lang="en">
    <head>
        <meta charset="UTF-8">
        <title>vue-router之实例操作新闻列表单页面应用与路由别名的使用</title>
        <script src="vue.js"></script>
        <script src="vue-router.js"></script>
    </head>
    <body>
    <div id="demo">
        <router-view></router-view>
    </div>
    <script type="text/x-template" id="home">
        <div>
            <li v-for="v in news">
                <router-link :to="{name:'content',params:{id:v.id}}">{{v.title}}</router-link>
            </li>
        </div>
    </script>
    <script type="text/x-template" id="content">
        <div>
            <h1>{{field.title}}--{{field.id}}</h1>
            <p>
                {{field.content}}
            </p>
            <router-link to="/">返回首页</router-link>
        </div>
    </script>
    <script>
        var data = [
            {id: 1, title: "php课程", content: "php是个比较牛的技术"},
            {id: 2, title: "java课程", content: "java是个比较牛的技术"}
        ]
        const home = {
            template: "#home",
            data() {
                return {
                    news: data
                }
            }
        }
        const content = {
            template: "#content",
            data() {
                return {
                    field: {}
                }
            },
            mounted() {
                var id = this.$route.params.id;
                for (let k = 0; k < data.length; k++) {
                    if (data[k].id == id) {
                        this.field = data[k];
                    }
                }
            }
        }
        let routes = [
            {path: '/', component: home},
            {path: '/content/:id', component: content, name: "content"}
        ];
        //把组件交给路由器:
        let router = new VueRouter({routes});
        new Vue({
            el: "#demo",
            router
        });
    </script>
    </body>
    </html>
    

      

  • 相关阅读:
    java 下载图片并传输(java自带 BASE64工具进行图片和字符串转换)
    MySQL的日期格式
    eclipse下查看maven下载的源码中文乱码问题
    Linux----部署
    python----logging
    python----pymysql
    vmware15 激活秘钥
    vmware15 激活秘钥
    Ubuntu18.04安装
    msyql45讲 20--幻读是什么,幻读有什么问题?
  • 原文地址:https://www.cnblogs.com/yiweiyihang/p/8303634.html
Copyright © 2020-2023  润新知