[Vue] Use Vue.js Watchers to Respond to Async Updates
Use watchers to keep an eye on your data. Watchers are methods that are invoked when the specified attribute changes. They are useful when you want to perform asynchronous operations in response to changing data.
<template>
<section class="container">
<item-description></item-description>
<h1 class="title">
{{message | capitalize}}
</h1>
<button @click="changeMessage" class="button">Change Message</button>
<hr>
<section>
<h2>Mouse event</h2>
<div>{{counter}}</div>
<div @mouseover="inc">Mouse over here to change counter</div>
</section>
<section>
<h2>Keyboard events</h2>
<form @submit.prevent="submit">
<input type="text"
v-model="firstName"
@keyup.enter="submit"
@keyup.alt.ctrl.shift.down="keyeventHandler"/>
<button v-bind:disabled="buttonDisabled">{{buttonText}}</button>
</form>
<div>
{{key}}
</div>
</section>
</section>
</template>
<style scoped>
.title
{
margin: 50px ;
}
</style>
<script>
import ItemDescription from '../components/item-description';
export default {
data() {
return {
message: 'this is my vue!',
counter: ,
key: "",
firstName: "",
buttonText: "Add"
}
},
computed: {
buttonDisabled: function() {
return this.firstName == "";
}
},
watch: {
firstName: function(){
this.buttonText = this.firstName !== "" ? "Add " + this.firstName : "Add Dinosaur";
}
},
components: {
ItemDescription
},
filters: {
capitalize(value) {
return value.charAt().toUpperCase() + value.slice().toLowerCase();
}
},
methods: {
changeMessage() {
this.message = "Updated message here!"
},
inc() {
this.counter += ;
},
keyeventHandler() {
this.key = "Ctrl + alt + shift + down is clicked"
},
submit() {
console.log("form is submitted, the value is", this.firstName);
}
}
}
</script>
[Vue] Use Vue.js Watchers to Respond to Async Updates的更多相关文章
- Vue过渡效果之JS过渡
前面的话 与CSS过渡不同,JS过渡主要通过事件进行触发.本文将详细介绍Vue过渡效果之JS过渡 事件钩子 JS过渡主要通过事件监听事件钩子来触发过渡,共包括如下的事件钩子 <transitio ...
- 使用 Vue 和 epub.js 制作电子书阅读器
ePub 简介 ePub 是一种电子书的标准格式,平时我看的电子书大部分是这种格式.在手机上我一般用"多看"阅读 ePub 电子书,在 Windows 上找不到用起来比较顺心的软件 ...
- socket应用(vue、node.js、M站)
socket应用(vue.node.js.M站) 前言:我们在做一些项目的时候需要做到实时变化, 比如我们有时候有需求会要求我们做一个类似于聊天室的页面 比如有些时候我们对某些东西进行点赞和刷票,需要 ...
- vue项目中主要文件的加载顺序(index.html、App.vue、main.js)
先后顺序: index.html > App.vue的export外的js代码 > main.js > App.vue的export里面的js代码 > Index.vue的ex ...
- vue.runtime.esm.js:593 [Vue warn]: Invalid prop: custom validator check failed for prop "value".报错解决
在uni中使用 picker组件,一直报错 vue.runtime.esm.js:593 [Vue warn]: Invalid prop: custom validator check failed ...
- 最新的vue没有dev-server.js文件,如何进行后台数据模拟?
https://blog.csdn.net/qq_34645412/article/details/78833860 https://blog.csdn.net/qq_34645412/article ...
- vue中eslintrc.js配置最详细介绍
本文是对vue项目中自带文件eslintrc.js的内容解析, 介绍了各个eslint配置项的作用,以及为什么这样设置. 比较详细,看完能对eslint有较为全面的了解,基本解除对该文件的疑惑. /* ...
- vue中使用js动画与velocity.js
一:vue中使用js动画 根据上一篇安装animate.css之后 vue中有动画的钩子函数,@before-enter是内容由无到有的时候自动监听触发的函数,函数会接收到参数el,这样可以动态设置样 ...
- vue中的js引入图片,必须require进来
需求:如何components里面的index.vue怎样能把assets里面的图片拿出来. 1.在img标签里面直接写上路径: <img src="../assets/a1.png& ...
随机推荐
- JavaScript--数据结构之栈
4.1栈是一种高效的数据结构,是一种特殊的列表.栈内元素只能通过列表的一端访问,也就称为栈顶.后入的先出的操作.Last in First out.所以他的访问每次是访问到栈顶的元素,要想访问其余的元 ...
- Node里面的对象创建问题
1.利用new Object()创建时 var a =new Object() a.b = 1 console.log(a) // 打印出来是[object Object] console.log(J ...
- Python Unittest模块测试执行
记录一下Unittest的测试执行相关的点 一.测试用例执行的几种方式 1.通过unittest.main()来执行测试用例的方式: if __name__ == "__main__&quo ...
- WCF 字节数据传输
准备工作 1.新建一个工程,添加一个WCF服务库, 然后公共的类库, 添加一个默认可序列化的的CompositeType类用于压缩. [Serializable] public class Compo ...
- [Javascript AST] 4. Continue: Report ESLint error
const disallowedMethods = ["log", "info", "warn", "error", & ...
- iptables转发安卓手机热点的数据到指定的端口
iptables转发安卓手机热点的数据到指定的端口 手机安装了VPN,可以上GOOGLE的那种.然后我打开手机的热点,连上笔记本,想让本本上个google 没想到被GFW挡住了.看了一下手机的网络工作 ...
- 内网使用 IPV6 之 TunnelBroker隧道(6in4)篇
内网使用 IPV6 之 TunnelBroker隧道(6in4)篇 据非专业网民推测 tunnelbroker isatap 和 6to4 貌似都需要公网,但有网民测试这位大作的方法可行.特别之处是 ...
- sqlite3-查看数据库
在做android开发的时候,有时候我们需要查看系统下的数据库,这时候我们可以使用下面的方法 1.数据库存放位置 data/data/package/databases/abc.db 2.导出数据库 ...
- 洛谷——P1096 Hanoi双塔问题
https://www.luogu.org/problem/show?pid=1096 题目描述 给定A.B.C三根足够长的细柱,在A柱上放有2n个中间有孔的圆盘,共有n个不同的尺寸,每个尺寸都有两个 ...
- 小贝_redis web管理界面工具安装
RedisWEB管理界面工具安装 一.概述 二.文件下载 三.安装过程 一.概述 1.因为redis是基于C/S的方式开发.也就是说,仅仅要满足于redis的client通信要求的,都能够作为redi ...