1.v-model是双向绑定,视图(View)和模型(Model)之间会互相影响。

既然是双向绑定,一定是在视图中可以修改数据,这样就限定了视图的元素类型。目前v-model的可使用元素有:

  • input

  • select

  • textarea

  • checkbox

  • radio

  • components(Vue中的自定义组件)

基本上除了最后一项,其它都是表单的输入项。

举例:

html:

<body>
<div id="app">
<!--双向绑定 -->
<input type="text" v-model="num"> <button v-on:click="num++">+</button>   <h1>
   我是<span v-text="name"></span><br>
   吃了{{num}}个人
  </h1>
  <span v-text="name"></span><br>
  <span v-html="name"></span>   <h1>开售以下课程</h1>
  <input type="checkbox" value="java" v-model="lessons"/>java<br>
  <input type="checkbox" value="python" v-model="lessons"/>python<br>
  <input type="checkbox" value="ios" v-model="lessons"/>ios<br>   <h1>您已经够卖</h1>
  <!--join()方法用于把数组中的所有元素放入一个字符串。元素是通过指定的分隔符进行分隔的-->
  {{lessons.join(",")}} </div>
  <script src="node_modules/vue/dist/vue.js"></script>
<script>
  const app = new Vue({
   el: "#app",//element
  data: { name: "大老虎",
      num: 1,
      lessons: []
  },
});
 </script>
</body>

2.v-on指令用于给页面元素绑定事件。

  另外,事件绑定可以简写,例如v-on:click='add'可以简写为@click='add'

<body>
<div id="app">
<!--v-on 绑定事件-->
  <!--单机弹出一个提示框-->
<button v-on:click="tips">点我</button>
<br>
   <!--单机按钮 但是不触发div的v-on 事件冒泡使用 v-on:click.stop="触发的事件" -->
<div style="height: 100px;width: 100px;background-color: aqua;" v-on:click="printf('div')">
<button v-on:click.stop="printf('button')">点我试试</button>
</div>
<!--单机超链接 不触发href的地址 使用 v-on:clikc.prenevt="触发的事件"-->
<a href="http://www.baidu.com" v-on:click.prevent="printf('百度一下')">百度一下</a>
</div> <script src="node_modules/vue/dist/vue.js"></script>
<script>
const app = new Vue({
el: "#app",
methods: {
tips: function () {
alert("hello");
}, created: function () {
this.name = "你好"
},
printf:function (msg) {
console.log(msg)
}
},
}); </script>
</body>

TZ_16_Vue的v-model和v-on的更多相关文章

  1. Oracle基本数据字典:v$database、v$instance、v$version、dba_objects

    v$database: 视图结构: SQL> desc v$database; Name                                      Null?    Type - ...

  2. POJ2762 Going from u to v or from v to u(单连通 缩点)

    判断图是否单连通,先用强连通分图处理,再拓扑排序,需注意: 符合要求的不一定是链拓扑排序列结果唯一,即在队列中的元素始终只有一个 #include<cstdio> #include< ...

  3. Going from u to v or from v to u?_POJ2762强连通+并查集缩点+拓扑排序

         Going from u to v or from v to u? Time Limit: 2000MS   Memory Limit: 65536K       Description I ...

  4. 临时文件相关的v$tempfile v$sort_usage与V$tempseg_usage

    SQL> select username,user,segtype,segfile#,segblk#,extents,segrfno# from v$sort_usage; SEGFILE#代表 ...

  5. [强连通分量] POJ 2762 Going from u to v or from v to u?

    Going from u to v or from v to u? Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 17089 ...

  6. POJ2762 Going from u to v or from v to u?(判定单连通图:强连通分量+缩点+拓扑排序)

    这道题要判断一张有向图是否是单连通图,即图中是否任意两点u和v都存在u到v或v到u的路径. 方法是,找出图中所有强连通分量,强连通分量上的点肯定也是满足单连通性的,然后对强连通分量进行缩点,缩点后就变 ...

  7. poj 2762 Going from u to v or from v to u?

    题目描述:为了让他们的儿子变得更勇敢些,Jiajia和Wind将他们带到一个大洞穴中.洞穴中有n个房间,有一些单向的通道连接某些房间.每次,Wind选择两个房间x和y,要求他们的一个儿子从一个房间走到 ...

  8. POJ 2762 Going from u to v or from v to u? (强连通分量缩点+拓扑排序)

    题目链接:http://poj.org/problem?id=2762 题意是 有t组样例,n个点m条有向边,取任意两个点u和v,问u能不能到v 或者v能不能到u,要是可以就输出Yes,否则输出No. ...

  9. poj 2762 Going from u to v or from v to u?(强连通分量+缩点重构图+拓扑排序)

    http://poj.org/problem?id=2762 Going from u to v or from v to u? Time Limit: 2000MS   Memory Limit:  ...

  10. POJ 2762 Going from u to v or from v to u?(强联通 + TopSort)

    题目大意: 为了锻炼自己的儿子 Jiajia 和Wind 把自己的儿子带入到一个洞穴内,洞穴有n个房间,洞穴的道路是单向的. 每一次Wind 选择两个房间  x 和 y,   让他的儿子从一个房间走到 ...

随机推荐

  1. uoj33 树上GCD

    题意:给你一棵树,根节点为1,每条边长度为1.定义f(u,v)=gcd(u-lca(u,v),lca(u,v)-v),求有多少个无序点对f(u,v)=i.对每个i输出答案. n<=20W. 标程 ...

  2. 使用了@Slf4j log没有info的方法 .info()方法爆红或者log爆红

    在springboot项目中,使用注解@Slf4j时,log变量不能用. 导包用的是 import lombok.extern.slf4j.Slf4j; <dependency> < ...

  3. leetcode-123-买卖股票的最佳时机③

    题目描述: 方法一: class Solution: def maxProfit(self, prices: List[int]) -> int: dp_i1_0 = 0 dp_i1_1 = f ...

  4. C++模拟实现Objective-C动态类型(附源码)

    在OC(Objective-C)里面有动态类型分为以下几类: -(BOOL)isKindOfClass:classObj 是否是classObj类或其子类 -(BOOL)isMemberOfClass ...

  5. HAVING方法也是连贯操作之一

    HAVING方法也是连贯操作之一,用于配合group方法完成从分组的结果中筛选(通常是聚合条件)数据. having方法只有一个参数,并且只能使用字符串,例如: $this->field('us ...

  6. springboot让内置tomcat失效

    一.POM(去除内嵌tomcat后,需要添加servlet依赖) <dependency> <groupId>org.springframework.boot</grou ...

  7. centos 7 安装dotnet core

    dotnetcore 支持的Linux 版本请看官网:https://docs.microsoft.com/zh-cn/dotnet/core/linux-prerequisites?tabs=net ...

  8. tab切换 -- vue

    效果: html: // 按钮<div class="orderTab clearfix" @click="toggle()"> <div c ...

  9. Windows下运行Tomcat闪退问题

    直接双击startup.bat后闪退,可能的原因是tomcat的配置没有完全正确 完整的tomcat的配置应该配置: 1.JAVA_HOME 2.CATALINA_HOME 3.Path:%CATAL ...

  10. flink第一个应用

    去年华为大佬就开始在用flink,今天刚有空就稍微跟着写了个demo玩起来(就不用java了 spark和flink还是用scala玩) package flink.testimport org.ap ...