v-model值为 [object HTMLInputElement]

来源:3-1 核心Composition API介绍

iHaroro

2021-03-29 17:41

我这边的v-model,怎么是 [object HTMLInputElement] ?Vue版本3.0.0-beta.1

http://img2.mukewang.com/6061a1170001dac307680086.jpg

<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"
  }
}


写回答 关注

1回答

  • iHaroro
    2021-03-29 18:15:46

    找到了,与ref有关

快速了解新版Vue3.0 + Vite开发

Vue3.0深入浅出,带你领略最新的开发神器Vite,助力Vue3.0开发

2257 学习 · 8 问题

查看课程

相似问题