0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

LaravelでVue.JSを使ってみる①

Last updated at Posted at 2020-09-12

環境構築

プロジェクト内でnpm installで利用可能(ver 5.6以降?デフォルトでpackage.jsonに設定してある)
※レンタルサーバーの場合はnode.js入れる必要がある。

$ npm install

実装してみる

とりあえず、welcome.blade.phpに設定してみます。

resources/views/welcome.blade.php

<html lang="{{ app()->getLocale() }}">
    <head>
      ~
     <meta name="csrf-token" content="{{ csrf_token() }}">
   <link href="{{ asset('css/app.css') }}" rel="stylesheet">
     ~
  </head>
  <body>
     ~
      <div id="app">
         <example-component></example-component>
      </div>
     ~
     <script src="{{ asset('js/app.js') }}" defer></script>
   </body>
</html>

①head内でcsrfトークンの設定、cssのリンク

<meta name="csrf-token" content="{{ csrf_token() }}">
<link href="{{ asset('css/app.css') }}" rel="stylesheet">

②body内でコンポーネントの設定

vueのコードはresources/assets/js/app.jsに書いてあります。example-componentはデフォルトで設定してあるコンポーネント

   <div id="app">
         <example-component></example-component>
      </div>

③body閉じタグ直前でjsファイルへのリンク

<script src="{{ asset('js/app.js') }}" defer></script>

動かしてみる

コンパイルしてページを開くと表示されているはずです。

$ npm run dev

npm run dev … minifyされない
npm run prod … minifyされる
npm run watch … 対象ファイルを監視して変更があれば自動でコンパイルしてくれる

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?