问答详情
源自:3-1 核心Composition API介绍

v-model值为 [object HTMLInputElement]

我这边的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"
  }
}


提问者:iHaroro 2021-03-29 17:41

个回答

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

    找到了,与ref有关