blade
1<table-draggable :users="{{ $users }}" ></table-draggable> 2 3 4<script> 5 jQuery(function($) { 6//削除ボタンが押されたら削除用Ajaxを呼び出す 7 $("table").on("click", ".del_btn", function() { 8 var url = "{{ route('admin.user.destory','') }}/" + $(this).data("id"); 9 deleteRecord(url, this); 10 }); 11 12}); 13</script> 14
vue
1 2<draggable :list='usersNew' :options="{animation:200,handle:'.my-handle'}" :element="'tbody'"> 3 <tr v-for="(user,index) in usersNew"> 4 <th>{{user.name}}</th> 5 <th>{{user.email}}</th> 6 <th>{{user.messages_count}}</th> 7 <th><input type="button" class="del_btn btn-outline-secondary" value="削除" **data-id={{user.id}}**></th> 8 <th><i class="fa fa-arrows my-handle"></i></th> 9 </tr> 10 </draggable> 11 12<script> 13 import draggable from 'vuedraggable' 14 export default { 15 components:{ 16 draggable 17 }, 18 props:['users'], 19 data:function(){ 20 return{ 21 usersNew:this.users, 22 } 23 }, 24 mounted() { 25 console.log('Component mounted.') 26 } 27 } 28</script>
LaravelでJqueryでAjaxを使って削除ボタンを押したら該当したtr行を削除するという動作は動くのですが、今からvue.jsのdraggableというライブラリを使ってテーブル全体をコンポーネント化して対象の行をクリックしてソートできるというような動きにしたいです。その際に元々bladeにあった thタグの中のinputタグのdata-id属性はどのようにvueの中でバインド?すればJqueryに再度読み込まれるのでしょうか、説明が悪くてすいませんがご教授いただければ幸いです。
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2020/03/09 04:21