?。。?!轉(zhuǎn)載請注明作者和本文鏈接?。。?!
PS:本文假設(shè)你已經(jīng)建好了laravel工程,有一點blade模板和vue的基礎(chǔ)
直接上步驟!
1.首先我們在 "工程目錄/ resources/assets/js/components" 目錄下新增一個Vue組件(也就是增加一個.vue文件)
比如Welcome.vue:
<template>
<div id="welcome">
<div>歡迎</div>
</div>
</template>
<script>
//這里寫本組件的js代碼
</script>
<style lang="scss">
//這里寫css
</style>
2.去"工程目錄/ resources/assets/js/app.js"里注冊組件
Vue.component('example-component', require('./components/ExampleComponent.vue'));
Vue.component('welcome', require('./components/Welcome.vue')); //在這里添加注冊,第一個是組件名,第二個參數(shù)是組件路徑
const app = new Vue({
el: '#app'
});
3.在blade模板里面加入一個id為app的標(biāo)簽,并在標(biāo)簽里面使用的組件名
@extends('Base.base')
@section('title','歡迎')
@section('pageStyle')
@stop
@section('content')
<div id="app"> <!--這里id為app,因為第二步app.js里面new Vue時用的el參數(shù)就是app-->
<welcome></welcome> <!--這里就是我們第二步注冊的welcome-->
</div>
@stop
@section('pageScript')
@stop
然后就OK了?。?!
!?。?!轉(zhuǎn)載請注明作者和本文鏈接?。。?!