Day17 - 上架後台的商品列表页,今天只铺了 template

<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,致独一无二的你

>>:  【D17】杂谈:版本与Github找不到资料

[ 卡卡 DAY 23 ] - React Native 表单套件用 Formik + Yup 验证 (上)

在网路上看到有人推荐 Formik 不仅符合 react native 也可以在 react 上使...

入门魔法 - 针对 DOM 节点的简单操作

前情提要 上回说了希望选择学习火属性魔法後,艾草带我走到一棵大树下。 艾草:「来尝试用自己现有的魔力...

Day19 vue.js之我的专案显示

延续昨日 今天从我的专案开始 老样子先新增一个project.vue 再来去加入新的path 然後先...

Day5:进入新手村前先让我复习一下QQ-CSS-flexbox-用在外层容器的属性

上一篇讲到的是基本概念的部分,Flexbox可以把它当成一个容器(Container)以及内容物(i...

day10 轨迹 (雷)没有就等着被电到飞上天

来部落格看图文并茂文章 补觉鸣诗 前面说防火墙 我们会设定 log 记录功能 而一般防火墙内建空间不...