「Php/laravel/laravel5/laravelmix/vue」の版間の差分
提供: 初心者エンジニアの簡易メモ
(→参照) |
(→example.vue定義場所) |
||
行29: | 行29: | ||
resources/assets/js/app.js | resources/assets/js/app.js | ||
Vue.component('example', require('./components/Example.vue')); | Vue.component('example', require('./components/Example.vue')); | ||
+ | |||
+ | resources/assets/js/components/Example.vue | ||
+ | <template> | ||
+ | <div class="container"> | ||
+ | <div class="row"> | ||
+ | <div class="col-md-8 col-md-offset-2"> | ||
+ | <div class="panel panel-default"> | ||
+ | <div class="panel-heading">Example Component</div> | ||
+ | <div class="panel-body"> | ||
+ | I'm an example component! | ||
+ | </div> | ||
+ | </div> | ||
+ | </div> | ||
+ | </div> | ||
+ | </div> | ||
+ | </template> | ||
+ | <script> | ||
+ | export default { | ||
+ | mounted() { | ||
+ | console.log('Component mounted.') | ||
+ | } | ||
+ | } | ||
+ | </script> | ||
==参照== | ==参照== | ||
http://blog.asial.co.jp/1496 | http://blog.asial.co.jp/1496 |
2018年1月18日 (木) 12:35時点における版
vue動作確認
laravel5.4以上にデフォで入ってるvueのexampleコンポーネントを表示
~.blade.php
<!doctype html> <html> <head> <meta charset="UTF-8"> <title>Hello Vue</title> <link rel="stylesheet" href="css/app.css"/> <script type="text/javascript"> window.Laravel = window.Laravel || {}; window.Laravel.csrfToken = "テンプレート:Csrf token()"; </script> </head> <body>
<example></example>
<script src="js/app.js"></script> </body> </html>
以下のように表示されれば成功 Example Component I'm an example component!
example.vue定義場所
resources/assets/js/app.js
Vue.component('example', require('./components/Example.vue'));
resources/assets/js/components/Example.vue
<template>
Example Component
I'm an example component!
</template> <script> export default { mounted() { console.log('Component mounted.') } } </script>