简体   繁体   English

Vue.js,连接字符串和变量的bootstrap-vue语法

[英]Vue.js, bootstrap-vue syntax of concatenating string and variable

I'm having a syntax issue with '="collapse-{{ product.id }}"' both in the b-button & b-collapse.我在 b-button 和 b-collapse 中都遇到了 '="collapse-{{ product.id }}"' 的语法问题。 How should this be formed?这应该如何形成? Just trying to create a unique ID that ties the button to the collapse tag.只是试图创建一个唯一的 ID,将按钮与折叠标签联系起来。

  <b-list-group  header="List Product 1">
    <b-list-group-item 
      :variant="product.inventoryStatus? 'success': 'danger'"
      style="min-width: 30%; max-width: 30%"
      :border-variant="product.inventoryStatus ? 'success' : 'danger'"
      align="center"
      v-for="product in productList" :key="product.id">
      <b-button v-b-toggle="collapse-{{ product.id }}" class="m-1">{{ product.name }}</b-button>
        <b-collapse id="collapse-{{ product.id }}">
          Price: {{ product.price }}<br>
          Brand: {{ product.brand }}<br>
          <p :bg-variant="product.inventoryStatus? 'success': 'danger'">{{product.inventoryStatus ? 'IN STOCK': 'OUT OF STOCK'}}</p>
          <table>
            <tr>
              <td>
                <b-button variant="danger" @click="deleteProduct(product.id)">
                <i class="fa fa-trash"></i></b-button>
              </td>
              <td>
                <UpdateProduct :product="product"/>
              </td>
            </tr>
          </table>
        </b-collapse>
    </b-list-group-item>
  </b-list-group>

You can create a method and pass the product.id to it and use the return value`您可以创建一个method并将product.id传递给它并使用return `

Live Demo现场演示

代码沙盒演示

:v-b-toggle="getToggleValue( product.id )"

and define method as:并将方法定义为:

methods: {
    getToggleValue(id) {
      return `collapse-${id}`;
    },
  },

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM