Vue 基本指令

mustache
//在 vue3.0中  template 可以直接使用标签 不需要在外层 加div
<template id="tem">
            <!--1 mustache 基本使用 -->
            <h2>{{message}}</h2>
            <!--2 表达式 -->
            <h2>{{count*10}}</h2>
            <!--3 可以调用函数 -->
            <h2>{{message.split(" ").reverse().join(" ")}}</h2>
            <h2>{{getReverseMessage()}}</h2>

            <!--4 三元运算符 -->
            <h2>{{isShow ? "hahah":"哈哈"}}</h2>
            <button @click="change">切换</button>

            <!-- 错误用法 -->
            <!-- <h2>{{var name ='tom'}}</h2>
            <h2>{{if(isShow){return 'hhh'}}}</h2> -->
    </template>
v-once

只会渲染初始的一次

 <div v-once>
                <h2 >{{count}}</h2>
                <h2>{{message}}</h2>
            </div>
v-text
<template id="tem">
            <h2 v-text="message"></h2>
            <!-- 效果相同 -->
            <h2>{{message}}</h2>
    </template>
v-html

少用 在网页上任意渲染 html 是危险的
在单文件组件里,scoped 的样式不会应用在 v-html 内部 需要额外的style样式

 <h2 v-html="message"></h2>
 // 哈哈哈
  <h2>{{message}}</h2>
  // message:`<span style="color:red; background: blue;" >哈哈哈</span>`

 message:`<span style="color:red; background: blue;" >哈哈哈</span>`
v-pre

跳过这个元素和它的子元素的编译过程。可以用来显示原始 Mustache 标签。跳过大量没有指令的节点会加快编译。
// 不知道 究竟有啥用

<h2 v-pre>{{message}}</h2>
// {{message}}
v-cloak

cloak 披风 隐蔽隐藏的意思
配合 [v-cloak] {
display: none;
}使用 隐藏 {{}} 不会出现 {{message}} 会等到处理完成后在展示

 <style>
        [v-cloak] {
            display: none;
        }
    </style>
 <template id="tem">
            <h2 v-text="message"></h2>
            <h2 v-cloak>{{message}}</h2>
    </template>
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值