gpt4 book ai didi

javascript - 更改 v-for 数组中每个元素的属性

转载 作者:搜寻专家 更新时间:2023-10-30 22:44:45 25 4
gpt4 key购买 nike

我正在尝试用 Vue 编写 javascript 的方式来解决问题。

考虑这种情况:

在 .vue template

 <button  v-on:click="biggerFont()" class="btn btn-s btn-default" type="button" name="button">A</button>

<div v-for="(tweet, index) in tweets">
<div class="each_tweet">
<textarea v-on:keyup="typing(index)"
v-model="tweet.content"
placeholder="What's happening now">{{ tweet.content }}</textarea>
</div>
</div>

在 .vue <script>

export default {
methods: {
biggerFont: function() {

//can I somehow use this.tweets.style.fontSize to influence all the fontSize?
document.getElementsByClassName("each_tweet").style.fontSize = "xx-large"
}
}
}

我的问题是:

  1. 如何更改 tweets 中文本区域每个值的字体大小? ?是否有影响这些 fontSize 的默认 Vue 方式?

我尝试使用 document.getElementsByClassName.style.fontSize 失败了而且这似乎不是 Vue 的方式。谢谢!

最佳答案

我相信 Vue 的做法是使用类和样式绑定(bind)。例如:

<textarea v-bind:class="{ big: enlarge}">{{item}}</textarea>

https://jsfiddle.net/e064m859/

关于javascript - 更改 v-for 数组中每个元素的属性,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43109912/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com