- html>
- <html lang="en">
- <head>
- <meta charset="UTF-8">
- <title>Documenttitle>
- <script src="../vue.js">script>
- head>
- <body>
- <div id="app">
-
- <div>{{fullName}}div>
- <div>{{age}}div>
- div>
-
- <script type="text/javascript">
-
- var vm = new Vue({
- el: "#app",
- data:{
- firstName:"jack",
- lastName:"lee",
- fullName:"jack lee",
- age:12
- },
- //属性调用时 {{fullName()}} 按方法调用 这种方式不推荐使用
- // methods:{
- // fullName:function(){
- // return this.firstName +" "+this.lastName
- // }
- // },
- // 计算属性 ctrl +/ 快速注释 属性有缓存
- // computed:{
- // fullName:function(){
- // console.log("computed 1");
- // return this.firstName +" "+this.lastName;
- // }
- // },
- //事件监听的方式实现 属性有缓存
- watch : {
- firstName: function(){
- console.log("计算了一次");
- this.fullName = this.firstName + " " +this.lastName;
- },
- lastName: function() {
- console.log("计算了一次");
- this.fullName = this.firstName + " " +this.lastName;
- }
-
- }
-
- })
- script>
- body>
- html>