vue基础 - 实例中的数据,事件和方法

本文通过一个简单的Vue.js实例,展示了如何使用Vue进行DOM操作,包括事件绑定、数据绑定及条件渲染等基本功能。介绍了Vue的数据响应式原理,并演示了如何在页面中动态更新数据。
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>vue - demo</title>
<script src="https://cdn.staticfile.org/vue/2.2.2/vue.min.js"></script>
</head>
<body>
  <div id="root">
    <!-- v-on:绑定事件,这里绑定了click事件 -->
    <div @click="headleClick">{{content}}</div>
    <!--几种打印方式-->
    <h1 v-html="content"></h1>
    <h1 v-text="content"></h1>
    <h1>{{msg}}</h1>
  </div>
  <script>
    new Vue({
      el:"#root",
      data:{
        content:"<h2>hello_content</h2>",
        msg:"hello_msg"
      },
      methods:{
        headleClick:function(){
          this.content = "world"//点击改变文本内容,一定要写在methods方法里
        }
      }
    })
  </script>
</body>
</html>

 

转载于:https://www.cnblogs.com/wangjiayi/p/10277652.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值