完整原文地址见简书https://www.jianshu.com/p/09f55406e5ce
本文内容提要
this指针 指的是对应的 Vue实例
【methods】插值表达式中 可以使用函数调用返回结果
【computed】计算属性的 用法
注意——computed模板 和 methods模板 其计算属性的区别
【watch】模板的 用法
【watch】 可以实现类似 【computed】的效果
当用
computed
和methods
都可以实现时,
推荐使用computed
,因为computed
有缓存机制;
当用computed
和watch
都可以实现时,
也推荐使用computed
,因为computed
编写开发起来更简洁;
this指针 指的是对应的 Vue实例
板块中的this指针
(下面以methods
板块为例),指的是Vue实例
:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Hello World! heheheheheheda</title>
<script src="https://unpkg.com/vue@next"></script>
</head>
<body>
<div id="heheApp"></div>
</body>
<script>
const app = Vue.createApp({
data() {
return {
heheString: