接續處理口袋餐廳清單右側的「移除」鈕功能。
(2)口袋餐廳清單-移除鈕
分為資料渲染與觸發方法兩部分說明。
1.「移除」鈕的限制
只能移除口袋餐廳清單(以下簡稱口袋清單)中該筆資料,即一次只能移除一筆所選的餐廳。
2.當清單中「移除」鈕被操作時
<template>
  ...
  <table class="table table-bordered">
    <thead>
      <tr>
        <th scope="col" class="table-secondary">品牌受眾</th>
        <th scope="col" class="table-secondary">品牌名稱</th>
        <th scope="col" class="table-secondary">地址</th>
        <th scope="col" class="table-warning">動作</th>
      </tr>
    </thead>
    <tbody>
      <tr v-for="item in userResList" v-bind:key="item">
        <td>{{ item.type }}</td>
        <td>{{ item.brandName }}</td>
        <td>{{ item.address }}</td>
        <td class="table-warning">
          <button type="button" @click="delPucket(item)">移除</button>
        </td>
      </tr>
    </tbody>
  </table>
  ...
</template>
<script>
...
export default {
  data() {
    return {
      restaurants: [],
      userResList: [],
      ...
      apiUserResUrl: "",
      ...
    };
  }
...
  methods: {
    ...
    delPucket(item) {
      axios.get(this.apiUserResUrl).then((res) => {
        console.log(res);
        const userData = res.data[0];
        const dataIndex = userData.userRestaurants.findIndex(
          (dataIndex) => dataIndex.brandName === item.brandName
        );
        userData.userRestaurants.splice(dataIndex, 1);
        axios
          .put(this.apiUserResIdUrl, userData)
          .then((res) => {
            console.log(res);
            alert("成功移除該筆餐廳");
            this.userPocket();
          })
          .catch((error) => {
            console.log(error);
            alert("該筆餐廳移除失敗,請洽網站管理員!");
          });
      });
    },
  },
  ...
};
</script>