【发布时间】:2021-02-08 00:33:27
【问题描述】:
我想分隔一个由逗号连接的字符串并将其单独存储跨标签,以便我可以获得单个值。
我正在使用 Php 在 Vuejs 中工作,并使用 Axios 从数据库中获取数据。我在数据库中有一个product_color 值,通过逗号连接,就像这样Red,Black, White 并想像PHP explode() 函数一样将它分开。
下面的代码
感谢并为糟糕的英语感到抱歉。
<div class="card p-5" v-for="(single, index) in singleProduct" :key="single.id">
<h5 class="colors">colors:
{{ single.product_color }}
//getting value like this Red,Black,White
<span class="color orange not-available" data-toggle="tooltip" title="Not In store"></span>
<span class="color green"></span>
<span class="color blue"></span>
</h5>
</div>
import axios from "axios";
export default {
name: 'product-detail',
data (){
return {
//data from api
singleProduct: [],
product_id: this.$route.params.product_id
}
},
created(){
this.fetchItem();
},
methods: {
/* eslint-disable no-unused-vars */
fetchItem(product_id) {
axios
.get(`http://localhost/vue/src/Api/api?action=fetchItem&product_id=${this.product_id}`)
.then((res) => {
console.log(res);
this.singleProduct = res.data.product_data;
})
.catch((err) => {
console.log(err);
});
},
}
}
【问题讨论】:
标签: javascript php jquery vue.js vuejs2