如何将“ Vue JS值转换为PHP值,并将PHP值转换为Vue JS值”?

时间:2019-09-25 03:18:32

标签: php laravel vue.js

可能吗? 任何人请帮助我。 如何将“ Vue JS值转换为PHP值,并将PHP值转换为Vue JS值”?

<span v-for="comment in post.comments"> <?php $ud = comment.userId; $commentUser = DB::table('users') ->where('users.id', '=', $ud) ->first(); ?> <div class="post-comment" style="border-bottom: 1px solid #e6e6e6;margin-left: 5px;"> <!-- <img :src="'{{Config::get('app.url')}}/BUproject/public/frontEnd/images/users/' + post.user.pic" alt="" class="profile-photo-sm" style=" margin-bottom: 5px; margin-top:4px;"/>--> <img src="{{asset('public/frontEnd/')}}/images/users/{{$commentUser->pic}}" alt="" class="profile-photo-sm" /> <p style="margin-right: 15px;"><a :href="'{{url('/timeline')}}/' + comment.slug" class="profile-link">@{{post.user.firstName | uppercase}} @{{post.user.lastName}}</a> @{{comment.comment}} </p> </div> </span>

1 个答案:

答案 0 :(得分:5)

您可以使用axios从数据库获取数据,而无需编写php。这样便可以使用vue.js中的axios从数据库获取数据。

<script>
 export default {
   data() {
      return {
        users: [],
     }
  },
    methods: {
      loadusers(){
        axios.get('users').then(response => this.users= response.data);
       },
   }
 },
    mounted() {
     this.loadusers();
  }
</script>

您的控制器:

public function index()
    {
      return User::all();
    }

您的web.php:

Route::resource('users', 'UserController');