我正在尝试在表内的数组上创建 .join()
。预期结果是每辆车(在下面的示例中)位于一排。
我尝试过使用 .join("\r\n")
和 .join("<br />")
,但它不起作用。我错过了什么?
new Vue({ el: "#table", data() { return { items: [ { firstname: "John", lastname: "Doe", cars: ["Ferrari", "Tesla"] }, { firstname: "Jane", lastname: "Doe", cars: ["BMW", "Civic"] }, { firstname: "Jack", lastname: "Doo", cars: ["Corsa", "Golf"] }, { firstname: "Julie", lastname: "Doo", cars: ["Fiesta", "Brasilia"] } ], fields: [ { key: "firstname", label: "First name" }, { key: "lastname", label: "Last name" }, { key: "cars", label: "Cars" } ] }; }, methods: { join() { for (let item of this.items) { item.cars = item.cars.join("<br />") } } } });
<script src="https://cdnjs.cloudflare.com/ajax/libs/vue/2.6.11/vue.min.js"></script> <script src="https://unpkg.com/bootstrap-vue@latest/dist/bootstrap-vue.js"></script> <div id="table"> <b-button @click="join">Join Array</b-button> <b-table :fields="fields" :items="items" /> </div>
与上面相同的代码片段,但在 CodePen 上。
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号