创建输入标签作为 v-model 的长度

huangapple go评论52阅读模式
英文:

Creating input tag as v-model's length

问题

<div v-if="quesType === 'Çoktan Seçmeli'" class="row p-3 bg-dark text-light">
  <div class="col-4">
    <select v-model="coktanSecmeli" class="form-select" name="" id="">
      <option value="3">3</option>
      <option value="4">4</option>
      <option value="5">5</option>
      <option value="6">6</option>
    </select>
  </div>
  <div v-for="item in coktanSecmeli">
    <input type="text"/>
  </div>
</div>

export default defineComponent({
name: "SoruEkle",
data() {
const quesType = "";
const coktanSecmeli = 0;
return {
quesType,
coktanSecmeli,
};
},
components: {
ErrorMessage,
Field,
Form,
},
props: {
widgetClasses: String,
},
methods: {},
});


<details>
<summary>英文:</summary>


<div v-if="quesType === 'Çoktan Seçmeli'" class="row p-3 bg-dark text-light">
<div class="col-4">
<select v-model="coktanSecmeli" class="form-select" name="" id="">
<option value="3">3</option>
<option value="4">4</option>
<option value="5">5</option>
<option value="6">6</option>
</select>
</div>
<div v-for="item in coktanSecmeli">
<input type="text"/>
</div>
</div>

export default defineComponent({
name: "SoruEkle",
data() {
const quesType = "";
const coktanSecmeli = 0;
return {
quesType,
coktanSecmeli,
};
},
components: {
ErrorMessage,
Field,
Form,
},
props: {
widgetClasses: String,
},
methods: {},
});


i tried but i cant fix this. how can i get v-model&#39;s length and use this length to create html tag as this model&#39;s length. i also tried with array and v-html but it didn&#39;t worked.

</details>


# 答案1
**得分**: 0

你需要为 `coktanSecmeli` 创建一个范围。让我们为这个目的定义一个计算属性:

```javascript
range() {
  return [...Array(this.coktanSecmeli).keys()];
}

或者使用标准语法:

range() {
  return Array.from(Array(this.coktanSecmeli).keys());
}

然后,你应该在 v-for 中使用这个范围:

<div v-for="key in range">
  <input type="text" :key="key"/>
</div>
英文:

You have to create a range for coktanSecmeli. Let's define computed property for this:

range() {
  return [...Array(this.coktanSecmeli).keys()];
}

or with a standard syntax:

range() {
  return Array.from(Array(this.coktanSecmeli).keys());
}

Then you should use this range for v-for:

&lt;div v-for=&quot;key in range&quot;&gt;
  &lt;input type=&quot;text&quot; :key=&quot;key&quot;/&gt;
&lt;/div&gt;

huangapple
  • 本文由 发表于 2023年2月6日 03:56:06
  • 转载请务必保留本文链接:https://go.coder-hub.com/75355097.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定