watch的用法,虽然没有报错,但是啥也没运行出来

news/2024/7/10 3:17:26 标签: vue

<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Vue的方法_侠课岛(9xkd.com)</title>

<script src="https://unpkg.com/vue@next"></script>
</head>
<body>
<template>
  <div>
    <button type="text">是多少:{{count}}</button>
    <button></button>
  </div>
</template>
<script>
import {reactive, toRefs, ref, watch} from 'vue'
export default {
  props: {
    select: Function,
  },

setup(props, ctx) {
  // 定义数据源
  const count = ref(0);
  // 指定要监视的数据源
  watch(count, (count, prevCount) => {
    console.log(count, prevCount)
  })
  setInterval(() => {
    count.value += 2
  }, 2000)
  console.log(count.value)
  return {
    count
  }
}
}
</script>
</body>
</html>

改了模板


<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Vue的方法_侠课岛(9xkd.com)</title>

<script src="https://unpkg.com/vue@next"></script>
</head>
<body>

  <div>
    <p >是多少:{{count}}</p>
    
  </div>

<script>
import {reactive, toRefs, ref, watch} from 'vue'
export default {
  props: {
    select: Function,
  },

setup(props, ctx) {
  // 定义数据源
  const count = ref(0);
  // 指定要监视的数据源
  watch(count, (count, prevCount) => {
    console.log(count, prevCount)
  })
  setInterval(() => {
    count.value += 2
  }, 2000)
  console.log(count.value)
  return {
    count
  }
}
}
</script>
</body>
</html>

能显示,但没有响应式,再改改。
这是html的文件,不是vue的。

用vite新建了vue,放进Helloworld.vue里了,也还是不行

<template>
  <div>
    <button>是多少:{{count}}</button>
    <button></button>
  </div>
</template>
<script>
import {reactive, toRefs, ref, watch} from 'vue'
export default {
  props: {
    select: Function,
  },

setup(props, ctx) {
  // 定义数据源
  const count = ref(0);
  // 指定要监视的数据源
  watch(count, (count, prevCount) => {
    console.log(count, prevCount)
  })
  setInterval(() => {
    count.value += 2
  }, 2000)
  console.log(count.value)
  return {
    count
  }
}
}
</script>

不知道错在哪里
倒是能运行,不报bug

我天,重新运行了一下,居然可以!!!
怎么就可以了呢?


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

相关文章

CentOS7中 命令安装GUI图形界面遇到报错Transaction check error处理

安装图形界面 yum groupinstall "GNOME 桌面" –y 注&#xff1a; 如果在控制台上操作&#xff08;或者没有中文环境&#xff09;&#xff0c;yum groupinstall “GNOME Desktop” -y PS: 安装过程如遇报错&#xff1a;Transaction check error: file /boot/efi/EFI…

启动nacos报错:No DataSource set

改一下数据库连接字符串的参数: ?characterEncodingutf8&zeroDateTimeBehaviorconvertToNull&useSSLfalse&useJDBCCompliantTimezoneShifttrue&useLegacyDatetimeCodefalse&serverTimezoneGMT%2B8&nullCatalogMeansCurrenttrue&allowPublicKeyRe…

watch,这个可以,不知道为什么可以,先记着吧

<template><div><button>是多少&#xff1a;{{count}}</button></div> </template> <script> import {reactive, toRefs, ref, watch} from vue export default {props: {select: Function,},setup(props, ctx) {// 定义数据源const…

CentOS 7命令行安装GNOME、KDE图形界面

正文 CentOS 7 默认是没有图形化界面的&#xff0c;但我们很多人在习惯了 Windows 的图形化界面之后&#xff0c;总是希望有一个图形化界面从而方便我们使用&#xff0c;这里介绍一下 CentOS&#xff17;安装图形化桌面系统的方法。 一、进入 root 模式 因为权限限制&#x…

好像也没有实现watch监听多个的功能,而且age也只更新了一次,不知道后面为什么不更新了

<template><div><button>是多少&#xff1a;{{age}}</button></div> </template> <script> import {reactive, toRefs, watch} from vue export default {props: {select: Function,}, setup(props, ctx) {const state reactive({ …

You have an error in your SQL syntax; check the man第二次出现这个问题了,语句放mysql里执行没问题.在springboot里执行报错..乜有语法问

You have an error in your SQL syntax; check the man第二次出现这个问题了,语句放mysql里执行没问题.在springboot里执行报错..乜有语法问题.也报语法问题. You have an error in your SQL syntax; check the man第二次出现这个问题了,语句放mysql里执行没问题.在springboot…

computed没成功,vue没有,js也没有。js说ref没定义

<template><div><button>是多少&#xff1a;{{count}}</button></div> </template> <script> import {ref, computed} from vue export default () { const count ref(1) const plusOne computed(() > count.value 1) } conso…

Invalid HTTP_HOST header: ‘xxx.xx.xxx.xxx:8000‘. You may need to add ‘xxx.xx‘ to ALLOWED_HOSTS

用python3 manage.py runserver 0.0.0.0:8000命令运行django程序后&#xff0c;通过浏览器访问服务器网址的8000端口&#xff0c;出现访问错误&#xff0c;报错为 Invalid HTTP_HOST header: ‘xxx.xx.xxx.xxx:8000’. You may need to add ‘xxx.xx’ to ALLOWED_HOSTS 解决…