<template>
<table class="table">
<thead>
<tr>
<th scope="col">排序</th>
<th scope="col">类别</th>
<th scope="col">商品名称</th>
<th scope="col">原价</th>
<th scope="col">售价</th>
<th scope="col">公开上架</th>
<th scope="col">编辑</th>
</tr>
</thead>
<tbody>
<tr v-for="(product, i) in productsList" :key="product.id">
<th scope="row">{{ i }}</th>
<td>{{ product.category }}</td>
<td>{{ product.origin_price }}</td>
<td>{{ product.title }}</td>
<td>{{ product.price }}</td>
<td>{{ product.enabled }}</td>
<td>
<button type="button" class="btn btn-primary me-2">编辑</button>
<button type="button" class="btn btn-outline-danger">删除</button>
</td>
</tr>
</tbody>
</table>
</template>
<script>
import axios from "axios";
export default {
name: "productsManageTable",
data() {
return {
token: "",
uuid: "---",
productsList: [],
};
},
methods: {
// 从资料库取得产品列表
getProductList() {
const api = `---`;
// 先从浏览器 cookie 取得 token
this.token = document.cookie.replace(
/(?:(?:^|.*;\s*)loginToken\s*=\s*([^;]*).*$)|^.*$/,
"$1"
);
// https://github.com/axios/axios#global-axios-defaults
// 并且 header 按照後端 api 文件的规格要求填上 Bearer token 字样
axios.defaults.headers.common.Authorization = `Bearer ${this.token}`;
axios
.get(api)
.then((res) => {
console.log(res);
this.productsList = res.data.data;
})
.catch((err) => {
console.log(err);
});
},
},
// 当元件被建立好,就先取得产品列表
created() {
this.getProductList();
},
};
</script>
上述内容有出入的话,希望大大们能在提点提点 (っಠ‿ಠ)っ
<<: DAY 18:Singleton Pattern,致独一无二的你
在网路上看到有人推荐 Formik 不仅符合 react native 也可以在 react 上使...
前情提要 上回说了希望选择学习火属性魔法後,艾草带我走到一棵大树下。 艾草:「来尝试用自己现有的魔力...
延续昨日 今天从我的专案开始 老样子先新增一个project.vue 再来去加入新的path 然後先...
上一篇讲到的是基本概念的部分,Flexbox可以把它当成一个容器(Container)以及内容物(i...
来部落格看图文并茂文章 补觉鸣诗 前面说防火墙 我们会设定 log 记录功能 而一般防火墙内建空间不...