Vue中指令 v-cloak v-text v-html v-bind v-on的使用

陛下,以下是代码

<!DOCTYPE html>
<html lang="en" xmlns:v-bind="http://www.w3.org/1999/xhtml" xmlns:v-on="http://www.w3.org/1999/xhtml" xmlns: xmlns:
      xmlns: xmlns:>
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <script src="https://cdn.jsdelivr.net/npm/vue/dist/vue.js"></script>
</head>
<body>
<div id="app">
    <!--使用 v-cloak 能够解决插值表达式的闪烁问题(网速很慢的时候,会显示{{msg}})-->
    <p v-cloak>{{msg}}</p>

    <!-- v-text 没有闪烁问题,但是会覆盖标签中的内容-->
    <h3 v-text="msg"></h3>

    <!-- v-html 渲染html标签-->
    <div v-html="msg2">
    </div>

    <!-- ( v-bind: == : ) 用于绑定属性的指令;可以写合法的js表达式 -->
    <input type="button" value="按钮:v-bind" v-bind:title="mytitle + 'jhh'">
    <input type="button" value="按钮::" :title="mytitle + 'xxx'">

    <!-- ( v-on: == @ ) 事件绑定机制-->
    <input type="button" value="弹窗" v-on:click="show"/>
    <input type="button" value="弹窗2" @click="show2"/>

</div>
<script>
    var vm = new Vue({
        el: "#app",
        data: {
            msg: "123",
            msg2: '<h1>我是一个大大的h1标签</h1>',
            mytitle: "这是我自己的title"
        },
        methods: {  // 定义当前控制区域中所有的方法
            show: function () {
                alert('Hello Vue');
            },
            show2: function () {
                alert('Hello too!')
            }
        }
    })
</script>
</body>
</html>
发布了62 篇原创文章 · 获赞 0 · 访问量 1247

猜你喜欢

转载自blog.csdn.net/weixin_45616246/article/details/105319744