我正在努力学习vue.js. 我正在添加元素列表,我想class="active"只添加到for循环中的第一个元素.以下是我的代码:
<div class="carousel-inner text-center " role="listbox">
<div class="item" v-for="sliderContent in sliderContents">
<h1>{{ sliderContent.title }}</h1>
<p v-html="sliderContent.paragraph"></p>
</div>
</div>
Run Code Online (Sandbox Code Playgroud)
所以第一个元素应该是这样的:
<div class="item active">
<h1>WELCOME TO CANVAS</h1>
<p>Create just what you need for your Perfect Website. Choose from a wide<br>range of Elements & simple put them on your own Canvas</p>
</div>
Run Code Online (Sandbox Code Playgroud)
我能够获取数据,所以一切都运行得很好.
以下是我的脚本代码:
<script>
export default{
data() {
return {
sliderContents: [
{
title: "WELCOME TO CANVAS",
paragraph: "Create just what you need for your Perfect Website. Choose from …Run Code Online (Sandbox Code Playgroud)