Vue.jsとlaravelでSPAのサービスを開発しています
実現したいこと
- LaravelのAPIから受けとったレスポンスの値をvueで表示したい
発生している問題・エラーメッセージ
画面の実装を
<template> <div> <div class="l-form"> <form v-on:submit.prevent="submit"> <div class="p-input"> <input id="search_word" type="textarea" :value="searchWord.search_word" class="c-input" name="search_word"> </div> <div class="p-buttonbox"> <button type="submit" class="c-button u-mt60"> 編集する </button> </div> </form> </div> </div> </template> <script> export default { props: { id: String }, data: function () { return { searchWord: [] } }, methods: { getSearchWord() { axios.get('/api/editWord/' + this.id) .then((res) => { this.searechWord = res.data; }); } }, mounted() { this.getSearchWord(); } } </script>
LaravelのAPIを
public function editWord($id){ if(!ctype_digit($id)){ return redirect('/home')->with('c_flash',__('Invalid operation was performed')); } $searchWord = DB::table('search_words')->where('id',$id)->first(); return $searchWord;
とし、ブラウザの開発ツールで以下のレスポンスが返ってきていることまでは
確認できています
{"id":8,"user_id":"1","search_word":"\u30ad\u30e3\u30ea\u30a2","twitter_account_id":"1563758613067284480","twitter_screen_name":"yurikosougotest","search_type":"2","scene_type":"1","created_at":"2022-10-12 16:24:08","updated_at":"2022-10-12 16:24:08"}
:value="searchWord.search_word"
で項目を指定する以外に必要な処理があるのでしょうか?
補足情報(FW/ツールのバージョンなど)
Laravel v8.83.23
PHP v7.4.18
"vue": "^2.5.17",
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。