我这边的v-model,怎么是 [object HTMLInputElement] ?Vue版本3.0.0-beta.1
<template> <div class="hello"> <input type="text" ref="num1" v-model="num1" @keyup="add()" /> <span>+</span> <input type="text" ref="num2" v-model="num2" @keyup="add()" /> <span>=</span> <span>{{result}}</span> </div> </template> <script> import { ref } from 'vue' export default { name: 'HelloWorld', setup () { let num1 = ref(0) let num2 = ref(0) let result = ref(0) function add () { return result = (+num1) + (+num2) } return { num1, num2, result, add, } }, } </script> <style scoped lang="scss"> </style>
{ "name": "vue3-demo", "version": "0.1.0", "private": true, "scripts": { "dev": "npm run serve", "serve": "vue-cli-service serve", "build": "vue-cli-service build" }, "dependencies": { "core-js": "^3.6.5", "vue": "^3.0.0-beta.1", "vue-router": "^4.0.0-alpha.6", "vuex": "^4.0.0-alpha.1" }, "devDependencies": { "@vue/cli-plugin-babel": "~4.5.0", "@vue/cli-plugin-router": "~4.5.0", "@vue/cli-plugin-vuex": "~4.5.0", "@vue/cli-service": "~4.5.0", "@vue/compiler-sfc": "^3.0.0-beta.1", "sass": "^1.26.5", "sass-loader": "^8.0.2", "vue-cli-plugin-vue-next": "~0.1.4" } }
找到了,与ref有关