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

标签 javascript css events vue.js

我正在尝试用 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 中文本区域每个值的字体大小?是否有默认的 Vue 方式来影响这些 fontSize?

我尝试使用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/

相关文章:

css - 在 Visual Studio Code 中使用tasks.json 来转译 typescript 和 sass

events - OCaml 事件/ channel 教程?

javascript - jquery - ajax 请求不工作

javascript - 非尺寸钻石设计用于在 html 和 css 中创建图像库

尽管使用嵌套 div 将高度设置为自动,但 CSS 仍然溢出

css - 由于@Font-Face 在 Chrome 中呈现问题

JAVA 从文本文件创建事件列表

python - 在 Python 2.7 中模拟按键事件

javascript - 如何在更改时附加 url

javascript - 如何使CSS动画按需向前或向后播放