:::: 개발 ::::/::: Vue:::

vue accessing the dynamic ref 다이나믹 ref 생성

nayha 2023. 8. 28. 18:25
<script>
    export default {
        data() {
            return {
                inputs: [
                    { id: Date.now(), name: '', lastName: '' }
                ]
            }
        },
        methods: {
            displayRef(ref) {
                console.log(this.$refs[ref]) // <= accessing the dynamic ref
                console.log('The value of input is:',this.$refs[ref][0].value) //<= outpouting value of input
            },
            displayAllRefs() {
                console.log(this.$refs)
            }
        }
    }
</script>

참조 : https://stackoverflow.com/questions/45563329/how-to-add-dynamic-ref-in-vue-js

반응형