[Vue] Use Vue.js Component Computed Properties
You can add computed properties to a component to calculate a property on the fly. The benefit of this over invoking a method is that computed properties are cached based on their dependencies.
<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 == "";
}
},
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 Component Computed Properties的更多相关文章
- Vue:Vue的介绍以及组件剖析
介绍 现在,随着基于JavaScript的单页应用程序(SPA)和服务器端渲染(SSR)的兴起,可以用JavaScript编写整个前端应用程序,并整洁地管理和维护该应用程序的前端代码.诸如Angula ...
- [Vue] Dynamic Vue.js Components with the component element
You can dynamically switch between components in a template by using the reserved <component> ...
- Vue.mixin Vue.extend(Vue.component)的原理与区别
1.本文将讲述 方法 Vue.extend Vue.mixin 与 new Vue({mixins:[], extend:{}})的区别与原理 先回顾一下 Vue.mixin 官网如下描述: Vue. ...
- vue教程2-03 vue计算属性的使用 computed
vue教程2-03 vue计算属性的使用 computed computed:{ b:function(){ //默认调用get return 值 } } ---------------------- ...
- Vue(七):computed计算属性
简介 计算属性关键词: computed. 计算属性在处理一些复杂逻辑时是很有用的. 实例1 可以看下以下反转字符串的例子: <div id="app"> {{ mes ...
- require.js 加载 vue组件 r.js 合并压缩
https://www.taoquns.com 自己搭的个人博客 require.js 参考阮一峰 Javascript模块化编程(三):require.js的用法 r.js 合并压缩 参考司徒正美 ...
- 19.VUE学习之- v-for与computed结合功能 筛选实例讲解
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...
- 前端笔记之Vue(七)Vue-router&axios&Vue插件&Mock.js&cookie|session&加密
一.Vue-router(路由) 1.1路由创建 官网:https://router.vuejs.org/zh/ 用 Vue.js + Vue Router 创建单页应用,是非常简单的.使用 Vue. ...
- 怎样理解 Vue 中的计算属性 computed 和 methods ?
需求: 在 Vue 中, 我们可以像下面这样通过在 引号 或 双花括号 内写 js 表达式去做一些简单运算, 这是可以的, 不过这样写是不直观的, 而且在 html 中 夹杂 一些运算逻辑这种做法其实 ...
随机推荐
- hibernate中的事务管理是怎么概念?
1.JDBC事务 JDBC 事务是用 Connection 对象控制的.JDBC Connection 接口( java.sql.Connection )提供了两种事务模式:自动提交和手工提交. ja ...
- 洛谷 P2978 [USACO10JAN]下午茶时间Tea Time
P2978 [USACO10JAN]下午茶时间Tea Time 题目描述 N (1 <= N <= 1000) cows, conveniently numbered 1..N all a ...
- Eclipse使用方法和技巧二十七:定义自己的高速联想词
某天在调试代码的时候.尽管是android的project还是习惯的输入syso.然后在ALT+/一下. 旁边的同事就问了一下,这个log打印输出的tag是什么. 接着又问了为什么syso可以智能联想 ...
- 转换PHP脚本成为windows的执行程序
转换PHP脚本成为windows的执行程序 Convert a PHP script into a stand-alone windows executable I want to automate ...
- python3输出range序列
b=range(3) #输出的是[0, 1, 2] ,其实这里如果用在循环上,代表着循环多少次,这里是循环3次.从零开始.print(list(b))
- 【hihocoder 1562】⼩Hi的钟表
[链接]点击打开链接 [题意] 在这里写题意 [题解] 时针每过1分钟转0.5°. (360/(12*60)) 分钟每过1分钟转6° (360/60); 根据这个就能算出时针和分针的角度之差了. [错 ...
- 关于python的深浅拷贝、赋值
https://blog.csdn.net/weixin_39750084/article/details/81435454
- Swiper+ ejs模板引擎+ iScroll插件知识总结
一. Swiper swiper是一个应用于移动端的动画插件,原理类似于轮播图 官网 http://www.swiper.com.cn/# html结构 <div class="swi ...
- JS学习笔记 - 点击、回车、ctrl+回车提交留言
疑点: oTxt1.onkeydown = function (ev) 为什么这里的onkeydown = function有变量 (ev),前面onclick函数没有? window.onload ...
- 2013腾讯编程马拉松||HDU 4505 小Q系列故事——电梯里的爱情 水水水
http://acm.hdu.edu.cn/showproblem.php?pid=4505 题目大意: 电梯最开始在0层,并且最后必须再回到0层才算一趟任务结束.假设在开始的时候已知电梯内的每个人要 ...