iT邦幫忙

2018 iT 邦幫忙鐵人賽
DAY 22
0
Modern Web

Laravel學習系列 第 22

LARAVEL學習 DAY 22 VUE.JS(六)

行 剩兩科 最快1/15開始補進度 以一天3篇的速度不知道夠不夠

LARAVEL學習 DAY 22 VUE.JS(六)

前言

正文

繼續貼code...
router

{
path: '/:id/edit',
component: require('./components/Edit')
}

edit

<template>
  <div class="container">
    <div class="form-group">
      <label for="title">標題</label>
      <input type="text" class="form-control" v-model="title">
    </div>
    <div class="form-group">
      <label for="content">內容</label>    
      <textarea class="form-control" name="content" cols="30" rows="10" v-model="content"></textarea>
    </div>
    <router-link class="btn btn-default" :to="`/${post.id}`">返回</router-link>
    <button type="button" class="btn btn-primary" @click="send">送出</button>
  </div>  
</template>

<script>
export default {
  data: () => {
    return {
      post: null,
      title: '',
      content: ''
    };
  },
  created() {
    const id = this.$route.params.id;
    axios.get(`api/crud/${id}`).then(response => {
      const post = response.data.post;
      this.post = post;
      this.title = post.title;
      this.content = post.content;
    });
  },
  methods: {
    send() {
      const title = this.title.trim();
      const content = this.content.trim();
      axios
        .put(`api/crud/${this.post.id}`, {
          title: title,
          content: content
        })
        .then(response => {
          const post = response.data.post;
          this.$router.push(`/${this.post.id}`);
        });
    }
  }
};
</script>

這次就是之前全部的結合 然後這篇就是vue的最後一篇了

結語

還剩8篇 我再來想想要講什麼玩意


上一篇
LARAVEL學習 DAY 21 VUE.JS(五)
下一篇
LARAVEL學習 DAY 23 新的開始 - Authentication(一)
系列文
Laravel學習30
圖片
  直播研討會
圖片
{{ item.channelVendor }} {{ item.webinarstarted }} |
{{ formatDate(item.duration) }}
直播中

1 則留言

0
kkdayy_55330
iT邦新手 5 級 ‧ 2019-08-12 15:07:58

能否分享這個範例的 github?

謝謝!

我要留言

立即登入留言