美文网首页
vue路由、v-html v-text v-once v-pre

vue路由、v-html v-text v-once v-pre

作者: 少女的愫语 | 来源:发表于2018-09-24 14:49 被阅读0次
路由vue-router
1)是vue的一个核心插件
2)可以根据不同的url访问不同的页面(进行不同页面的跳转)
3)创建单页面应用[又叫做SPA(SINGLE PAGE APP LICATION)应用]

简单路由

<div class="box">
            <router-link to="/home">首页</router-link>
            <router-link to="/bag">用户页</router-link>
            <router-view></router-view>
        </div>
        <script type="text/javascript" src="js/vue.js" ></script>
        <script type="text/javascript" src="js/vue-router.js" ></script>
        <script>
            var Home={
                template:`
                    <h1>欢迎来到我的网站</h1>
                `
            }
            var Bag={
                template:`
                    <h1>进入用户页面</h1>
                `
            }
            const routes=[
                {path:"/",compontent:Home},
                {path:"/home",component:Home},
                {path:"/bag",component:Bag}
            ]
            const router=new VueRouter({
                routes:routes
            })
            
            new Vue({
                el:".box",
                router:router
            })
        </script>

当点击是字体点颜色

``css
               <style>
            /*.active{
                color:orange;
            }*/
            .router-link-active{
                color: orange;
            }
        </style>
``html
               <div class="box">
            <router-link to="/home">首页</router-link>
            <router-link to="/bag">用户页</router-link>
            <router-view></router-view>
        </div>
``js
                <script type="text/javascript" src="js/vue.js" ></script>
        <script type="text/javascript" src="js/vue-router.js" ></script>
        <script>
            var Home={
                template:`
                    <h1>欢迎来到我的网站</h1>
                `
            }
            var Bag={
                template:`
                    <h1>进入用户页面</h1>
                `
            }
            const routes=[
                {path:"/",compontent:Home},
                {path:"/home",component:Home},
                {path:"/bag",component:Bag}
            ]
            const router=new VueRouter({
                routes:routes,
                /*linkActiveClass:"active"*/
            })
            
            new Vue({
                el:".box",
                router:router
            })
        </script>

路由的嵌套

<div class="box">
            <router-link to="/home">首页</router-link>
            <router-link to="/bag">用户页</router-link>
            <router-view></router-view>
            
        </div>
        <script type="text/javascript" src="js/vue.js" ></script>
        <script type="text/javascript" src="js/vue-router.js" ></script>
        <script>
            var home={
                template:`
                    <h1>欢迎来到我的网站</h1>
                `
            }
            var bag={
                template:`
                   <div>
                        <h1>欢迎来到我的用户页</h1>
                        <ul>
                            <li>
                                <router-link to="/bag/zhu">注册</router-link>
                            </li>
                            <li>
                                <router-link to="/bag/deng">登录</router-link>
                            </li>
                        </ul>
                        <router-view></router-view>
                    </div> 
                `
            }
            var zhu={
                template:`
                    <h1>欢迎来到我的注册</h1>
                `
            }
            var deng={
                template:`
                    <h1>欢迎来到我的登录</h1>
                `
            }
            const routes=[
                {path:'/',component:home},
                {path:"/home",component:home},
                {
                    path:"/bag",
                    component:bag,
                    children:[
                        {path:"zhu",component:zhu},
                        {path:"deng",component:deng}
                    ]
                }
            ]
            const router=new VueRouter({
                routes:routes
            })
            new Vue({
                el:".box",
                router:router
            })
        </script>
不常用的五个标签

v-html 可以识别标签
v-text 不识别标签按文本输入
v-once 只绑定第一次
v-pre 原样输出不对数据进行解译
v-clock 数据没有完全加载之前 加载完v-clock就消失了

<div class="box">
            <input type="text" v-model="msg" />
            <p v-html="msg">{{msg}}</p>
            <h2 v-text="msg">{{msg}}</h2>
            <h4 v-once>{{msg}}</h4>
            <h6 v-pre>{{msg}}</h6>
            <h5 v-cloak>{{msg}}</h5>
        </div>
        <script type="text/javascript" src="js/vue.js" ></script>
        <script>
            new Vue({
                el:".box",
                data:{
                    msg:'hello'
                },
                beforeMount:function(){ 
                  alert('beforeMount')
                }
            })
        </script>

相关文章

  • 2018-09-26 指令

    v-html,v-text,v-once,v-pre v-cloak

  • 补充Vue指令和路由

    v-html:自动识别输入的信息。v-text:原样输出。v-once:只绑定一次。v-pre:原样输出。 路由:...

  • Vue基础语法(逻辑相关)

    上期回顾 Mustache语法 v-once语法 v-html语法 v-text语法和v-pre语法 v-bind...

  • 指令

    v-once v-html v-bind v-if v-show v-text v-pre v-cloak v-o...

  • 补充

    v-html 可以识别html标签v-text 不可以识别html标签 v-once 只绑定一次v-pre ...

  • 2018-09-17 v-的其他指令

    v-text 输出渲染后的值 v-html 输出解析HTML元素后的值 v-once 只绑定一次 v-pre ...

  • V-事件补充

    v-html 可以识别html标签v-text 不可以识别html标签 v-once 只绑定一次v-pre 原样输...

  • vue

    v-once:只执行一次 v-html:用来展示带标签的字符串 v-text:会覆盖已存在的文本 v-pre:不显...

  • v-text,v-html,v-once,v-pre指令

    1.v-text,v-html,v-once,v-pre指令

  • VUE补充指令与路由

    VUE除了主要的那些重要指令,还有几个不重要的指令需要了解。v-html v-once v-pre ...

网友评论

      本文标题:vue路由、v-html v-text v-once v-pre

      本文链接:https://www.haomeiwen.com/subject/fnocoftx.html