使用vue js的数据转到laravel控制器

时间:2017-02-18 10:00:37

标签: laravel routes vue.js

这是我的vue

new Vue({
              el: '#notificationMenu',
              data: {
                showModal: false,
                patients: [],
                duepatients: []
              },
                created: function(){
                    this.getPatients();
                    this.addUsers();
                },
                methods: {
                    getPatients: function(){
                           $.getJSON("{{route('api_patients')}}", function(patients){
                            this.patients = patients;
                        }.bind(this));
                        setTimeout(this.getPatients, 1000); 
                    },
                    addUsers: function(){
                      this.$http.get('/govaccine/addUsers', '').then((response) => {

                      }, (response) => {
                        this.formErrors = response.data;
                        });

                       setTimeout(this.addUsers, 10000);                          
                    },sendSMS: function(val){

                      $.getJSON('sendsms/' + val,function(duepatient){
                            this.duepatients = duepatient;
                      }.bind(this));

                    }
                }

            });

这是我的HTML

<ul class="notifications-list" v-for="patient in patients">
                        <li class="item no-data">You don't have notifications</li>

                                <!-- use the modal component, pass in the prop -->
                          <modal v-if="showModal" @close="showModal = false">
                            <!--
                              you can use custom content here to overwrite
                              default content
                            -->
                            <h3 slot="header">custom header</h3>
                          </modal>
                            <a v-on:click="sendSMS(patient.due_date)">
                                <li class="item js-item " data-id="5" >
                                    <div class="details">
                                        <strong>@{{ patient.total}} patients</strong> are due for immunization on @{{patient.due_date}}
                                        <span class="date">{{--  @{{patient.created_at}} --}}</span>

                                    </div>
                                    <button type="button" class="button-default button-dismiss js-dismiss">×</button>
                                </li>
                            </a>
                    </ul> 

如果我使用v-for遍历vue js数据,我如何在{{route('patient.show',参数)}}中传递每个循环的数据,这样我就可以在其上放置一个参数。

或者无论如何要去控制器并转到另一页?

1 个答案:

答案 0 :(得分:0)

是的,你应该使用router-link。完整示例here。  如果我提出错误的问题,请告诉我。