hug-sun / element3

A Vue.js 3.0 UI Toolkit for IT Education. Build with JS&TS
https://e3.shengxinjing.cn/
MIT License
3.28k stars 1.01k forks source link

El-Form: vue ref attribute overlaps field with the same name #595

Closed bearbattle closed 2 years ago

bearbattle commented 3 years ago

Bug description

When using <el-form>, giving the form with ref attribute the same as model attribute would cause inappropriate behaviour of accessing data field associated with the model attribute.

What is the current behavior?

Given the code below:

<template>
    <el-form
        ref="form"
        :model="form"
    >
    </el-form>
</template>

<script lang="ts">
import { defineComponent, reactive } from 'vue'
export default defineComponent({
  name: 'BugReport',
  setup() {
    const form = reactive({ foo: 'bar'})
    return {
      form,
    }
  },
  mounted() {
    console.log(this.form) // This gives the content of *`<el-form>`* rather than `{foo: 'bar'}`
  }
})
</script>

What is the expected behavior?

this.form should provide the content of filed previously defined.

Steps to Reproduce

Refer to code above.

Live Demo:

Bug Report for Element3

Environment

shawroger commented 3 years ago

Perhaps it can be in this way.

Avoid using option-style mounted api, use onMounted instead.

import { defineComponent, reactive, onMounted } from 'vue'
export default defineComponent({
  name: 'BugReport',
  setup() {
    const form = reactive({ foo: 'bar'})
    onMounted(() => console.log(form));
    return {
      form,
    }
  },
})