vue vue对象的一些基础特性

1.vue 对象的标签内容扩展和标记信息的添加

(1).

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>vue 标签内容扩展及标注信息的添加</title>
</head>
<body>
    <div id="a">
        <message title="This is a title" content='This is content'></message>
        <message title="This is a title" content='This is content'></message>
        <message title="This is a title" content='This is content'></message>
        <message title="This is a title" content='This is content'></message>
        <message title="This is a title" content='This is content'></message>
        <message title="This is a title" content='This is content'></message>
    </div>

    <script src="vue.min.js"></script>
    <script>
        Vue.component("message",{
            props:["title","content"],
            data:function(){
                return {author:"where autor are "}
            },
            template:"<div><h1>{{title}}</h1><p>{{content}}</p><hr>{{author}}</div>"
        });
        new Vue({
            el:"#a"
        })
    </script>
</body>
</html>

效果:

image.png

2.vue 替换一个标签

(1).

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>vue 替换一个标签</title>
</head>
<body>
    <div id="a">
        <p>123333</p>
    </div>
    <script id="tpl">
        
    <div>
        <p>This is from tpl</p>
    </div>

    </script>

    <script src="vue.min.js"></script>
    <script>
        new Vue({
            el:"#a",
            template:"#tpl"
        });
    </script>
</body>
</html>

效果:

image.png

3.vue vue对象的数据绑定和生命周期

(1).

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>vue vue对象的数据绑定和生命周期</title>
    <style>
        .class0{
            background: skyblue;
            color: black;
        }
    </style>
</head>
<body>
    <div id="a">
        {{name}}
        <a :href="avatar" :class="'class'+count[0]" target="__blank">哔哩哔哩动画</a>
    </div>

    <script src="vue.min.js"></script>
    <script>
        var vm = new Vue({
            el:"#a",
            data:{
                name:"hahahah",
                avatar:"https://www.bilibili.com/",
                count:[0,2,3,5,8,9,4],
                message:"hehe"
            },
            beforeCreate:function(){
                console.log("beforeCreate");
            },
            created:function(){
                console.log("created");
            },
            beforeMount:function(){
                console.log("beforeMount");
            },
            mounted:function(){
                console.log("mounted");
            },
            beforeUpdate:function(){
                console.log("beforeUpdate");
            },
            updated:function(){
                console.log("updated");
            }
        });
    </script>
</body>
</html>

效果:

image.png

4.vue 一个vue对象的计算属性

(1).

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>vue 一个vue对象的计算属性</title>
</head>
<body>
    <div id="a">
        <p>{{f1}}</p>
        <p>{{f2}}</p>
        <p>{{f3}}</p>
    </div>

    <script src="vue.min.js"></script>
    <script>
        var vm = new Vue({
            el:"#a",
            data:{
                f1:"aaaa",
                f2:"bbbbb"
            },
            computed:{
                f3:function(){
                    return this.f1+" "+this.f2
                }

            }
        });
    </script>
</body>
</html>

效果:

image.png
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容

  • Spring Cloud为开发人员提供了快速构建分布式系统中一些常见模式的工具(例如配置管理,服务发现,断路器,智...
    卡卡罗2017阅读 135,682评论 19 139
  • 国家电网公司企业标准(Q/GDW)- 面向对象的用电信息数据交换协议 - 报批稿:20170802 前言: 排版 ...
    庭说阅读 13,880评论 6 13
  • 以下内容是我在学习和研究Vue时,对Vue的特性、重点和注意事项的提取、精练和总结,可以做为Vue特性的字典; 1...
    科研者阅读 14,772评论 3 24
  • 近日,越来越感觉烦闷,倒也没其他的事,就是无聊,这个年过的。 今年过年没回去,一个人在深圳默默的过了一个年,也没什...
    混账东西阅读 1,794评论 0 0
  • 李玲玲最近开始了一段婚外恋,不过她觉得这根本算不上是“恋”,他们之间充其量也就是联系比较频繁的炮友罢了。 我听完了...
    吃不吃花阅读 3,161评论 0 1