computed计算属性的用法,模模糊糊;后,用methods也可,为什么

news/2024/7/9 23:46:19 标签: vue

<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Vue的方法_侠课岛(9xkd.com)</title>
<script src="https://unpkg.com/vue@next"></script>
</head>
<body>
    <div id="computed-basics">
        <p>Has published books:</p>
        <span>{{ publishedBooksMessage }}</span>
      </div>
    <script>
Vue.createApp({
  data() {
    return {
      author: {
        name: 'John Doe',
        books: [
          'Vue 2 - Advanced Guide',
          'Vue 3 - Basic Guide',
          'Vue 4 - The Mystery'
        ]
      }
    }
  },
  computed: {
    // 计算属性的 getter
    publishedBooksMessage() {
      // `this` 指向 vm 实例
      return this.author.books.length > 0 ? 'Yes' : 'No'
    }
  }
}).mount('#computed-basics')
    </script>

    <style>
        .demo {
  font-family: sans-serif;
  border: 1px solid #eee;
  border-radius: 2px;
  padding: 20px 30px;
  margin-top: 1em;
  margin-bottom: 40px;
  user-select: none;
  overflow-x: auto;
}
    </style>
</body>
</html>

methods:


<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Vue的方法_侠课岛(9xkd.com)</title>
<script src="https://unpkg.com/vue@next"></script>
</head>
<body>
    <div id="computed-basics">
        <p>Has published books:</p>
        <p>{{ calculateBooksMessage() }}</p>
      </div>
    <script>
Vue.createApp({
  data() {
    return {
      author: {
        name: 'John Doe',
        books: [
          'Vue 2 - Advanced Guide',
          'Vue 3 - Basic Guide',
          'Vue 4 - The Mystery'
        ]
      }
    }
  },
// 在组件中
methods: {
  calculateBooksMessage() {
    return this.author.books.length > 0 ? 'Yes' : 'No'


    }
  }
}).mount('#computed-basics')
    </script>

    <style>
        .demo {
  font-family: sans-serif;
  border: 1px solid #eee;
  border-radius: 2px;
  padding: 20px 30px;
  margin-top: 1em;
  margin-bottom: 40px;
  user-select: none;
  overflow-x: auto;
}
    </style>
</body>
</html>

是否需要有缓存的关系,methods,不希望有缓存。
没有缓存,就一直更新?
有缓存,就不更新?


http://www.niftyadmin.cn/n/957804.html

相关文章

java实现大文件下载(http方式)

java实现大文件下载&#xff0c;基于http方式&#xff0c;控件神马的就不说了。 思路&#xff1a;下载文件无非要读取文件然后写文件&#xff0c;主要这两个步骤&#xff0c;主要难点&#xff1a; 1.读文件&#xff0c;就是硬盘到内存的过程&#xff0c;由于jdk内存限制&#x…

用命令创建MySQL数据库

一、连接MYSQL 格式&#xff1a; mysql -h主机地址 -u用户名 -p用户密码 1、 连接到本机上的MYSQL。 首先打开DOS窗口&#xff0c;然后进入目录mysql\bin&#xff0c;再键入命令mysql -u root -p&#xff0c;回车后提示你输密码.注意用户名前可以有空格也可以没有空格&#xff…

java文件处理(3)——实现文件复制和文件移动

任务要求&#xff1a; 通过二进制流的操作方式把程序调整为可以实现对任何类型文件进行文件复制&#xff08;而不是调用windows命令行的内部命令copy&#xff09;。 通过二进制流的操作方式把程序调整为可以实现对任何类型文件进行文件移动&#xff08;而不是调用windows命令行…

计算属性的setter,getter不懂

计算属性的 Setter 计算属性默认只有 getterhttps://v3.cn.vuejs.org/guide/computed.html#%E8%AE%A1%E7%AE%97%E5%B1%9E%E6%80%A7%E7%BC%93%E5%AD%98-vs-%E6%96%B9%E6%B3%95

Windows10系统下,彻底删除卸载MySQL

本文介绍&#xff0c;在Windows10系统下&#xff0c;如何彻底删除卸载MySQL。。。 1》停止MySQL服务 开始-》所有应用-》Windows管理工具-》服务&#xff0c;将MySQL服务停止。 2》卸载mysql server 控制面板\所有控制面板项\程序和功能&#xff0c;将mysql server卸载掉。 3》…

idea Error running EscpFormApplication. Command line is too long. Shorten the command line via JAR

idea Error running EscpFormApplication. Command line is too long. Shorten the command line via JAR manifest or via a classpath file and rerun. 个人博客里面还有其他idea报错教程&#xff0c;需要的同学可以点击下面链接 Idea运行报错Error running Application: Com…

watch这个没懂,是什么意思,是在干啥?

<!DOCTYPE html> <html> <head> <meta charset"utf-8"> <title>Vue的方法_侠课岛(9xkd.com)</title> <script src"https://unpkg.com/vuenext"></script> <script src"https://cdn.jsdelivr.net/…

windows下mysql 修改数据库data存放位置

一.首先把mysql的服务先停掉。 win10系统下&#xff0c;在管理工具中打开服务&#xff0c;找到mysql&#xff08;版本不同名字不同&#xff0c;比如mysql80&#xff09;&#xff0c;停止服务。 二.更改MySQL配置文件My.ini中的数据库存储主路径 不同版本的my.ini位置不同&a…