亚洲国产日韩欧美一区二区三区,精品亚洲国产成人av在线,国产99视频精品免视看7,99国产精品久久久久久久成人热,欧美日韩亚洲国产综合乱

ComboBox template component using VueJS
P粉550323338
P粉550323338 2023-09-03 22:34:50
0
1
603
<p>我想使用 <code>vuejs v3</code> 制作一個 <strong>Combobox</strong> 模板組件,為此我有以下代碼:</p> <pre class="brush:html;toolbar:false;"><template> <select name={{selector_name}} class= "combobox" id={{selector_id}}> v-for=opt in {{selector_options}} <option value=opt> opt </option> </select> </template> <script> export default { name: 'ComboBox', data() { return { selector_name: null, selector_id: null, selector_options : null, } }, props: { selector_name: { type: String, required: true }, selector_id: { type: String, default: "combobox" }, selector_options: { type: Array, required: true } }, methods: { onChange: (event) => { console.log(event.target.value); }, }, computed: {}, } </script> </pre> <p>但是我使用 <code>v-for</code> 的方式對我來說似乎不正確,你能告訴我如何糾正嗎?提前致謝。</p>
P粉550323338
P粉550323338

reply all(1)
P粉616111038

I see a lot of stuff, to answer your question clearly, v-for is used on elements.

<template>
    // For mor readability i recommend you do bind your property:
    //  - name={{selector_name}} become :name="selector_name"
    <select :name="selector_name" class= "combobox" :id="selector_id">
        <!-- v-for is required with a unique key, you can take the index and use it -->
        <option v-for="(opt, index) in selector_options" :key="`opt ${index}`" value=opt>
           {{ opt }}
        </option>
    </select>
</template>

You cannot define props and data with the same name. Props, inject properties and values ??into the data. Exactly the same, but the data comes from the parent and you pass values ??from the parent to the child.

So if you need to pass data, use props, but don't define it inside the data.

There is a working example of all of this (I'm using data instead of props to improve readability).

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template