質問をすることでしか得られない、回答やアドバイスがある。

15分調べてもわからないことは、質問しよう!

新規登録して質問してみよう
ただいま回答率
85.49%
Vue.js

Vue.jsは、Webアプリケーションのインターフェースを構築するためのオープンソースJavaScriptフレームワークです。

PHP

PHPは、Webサイト構築に特化して開発されたプログラミング言語です。大きな特徴のひとつは、HTMLに直接プログラムを埋め込むことができるという点です。PHPを用いることで、HTMLを動的コンテンツとして出力できます。HTMLがそのままブラウザに表示されるのに対し、PHPプログラムはサーバ側で実行された結果がブラウザに表示されるため、PHPスクリプトは「サーバサイドスクリプト」と呼ばれています。

Laravel 5

Laravel 5は、PHPフレームワークLaravelの最新バージョンで、2014年11月に発表予定です。ディレクトリ構造がが現行版より大幅に変更されるほか、メソッドインジェクションやFormRequestの利用が可能になります。

Q&A

1回答

676閲覧

LaravelのプロジェクトでVue.jsのテンプレートが表示されない

Linkey

総合スコア77

Vue.js

Vue.jsは、Webアプリケーションのインターフェースを構築するためのオープンソースJavaScriptフレームワークです。

PHP

PHPは、Webサイト構築に特化して開発されたプログラミング言語です。大きな特徴のひとつは、HTMLに直接プログラムを埋め込むことができるという点です。PHPを用いることで、HTMLを動的コンテンツとして出力できます。HTMLがそのままブラウザに表示されるのに対し、PHPプログラムはサーバ側で実行された結果がブラウザに表示されるため、PHPスクリプトは「サーバサイドスクリプト」と呼ばれています。

Laravel 5

Laravel 5は、PHPフレームワークLaravelの最新バージョンで、2014年11月に発表予定です。ディレクトリ構造がが現行版より大幅に変更されるほか、メソッドインジェクションやFormRequestの利用が可能になります。

1グッド

0クリップ

投稿2018/12/30 04:35

編集2018/12/30 04:56

Laravelを勉強しているものです。

以下の動画を参考にphpにVue.jsのテンプレートを反映させようとしているのですがうまくいきません。
https://www.youtube.com/watch?v=DJ6PD_jBtU0

app.jsの中身
イメージ説明

Articles.vueの中身
イメージ説明

web.phpの中身
イメージ説明

welcome.blade.phpの中身
イメージ説明

アクセスしたときに表示されたページ
イメージ説明

ソースコードです。
app.js

javascript

1 2/** 3 * First we will load all of this project's JavaScript dependencies which 4 * includes Vue and other libraries. It is a great starting point when 5 * building robust, powerful web applications using Vue and Laravel. 6 */ 7 8require('./bootstrap'); 9 10window.Vue = require('vue'); 11 12/** 13 * The following block of code may be used to automatically register your 14 * Vue components. It will recursively scan this directory for the Vue 15 * components and automatically register them with their "basename". 16 * 17 * Eg. ./components/ExampleComponent.vue -> <example-component></example-component> 18 */ 19 20// const files = require.context('./', true, /.vue$/i) 21// files.keys().map(key => Vue.component(key.split('/').pop().split('.')[0], files(key).default)) 22 23// Vue.component( 24// 'example-component', 25// require('./components/ExampleComponent.vue') 26// ); 27Vue.component( 28 'articles', 29 require('./components/Articles.vue') 30); 31 32/** 33 * Next, we will create a fresh Vue application instance and attach it to 34 * the page. Then, you may begin adding components to this application 35 * or customize the JavaScript scaffolding to fit your unique needs. 36 */ 37 38const app = new Vue({ 39 el: '#app' 40}); 41

Articles.vue

vue

1<template> 2 <div> 3 <h2>Articles</h2> 4 </div> 5</template>

web.php

php

1<?php 2 3/* 4|-------------------------------------------------------------------------- 5| Web Routes 6|-------------------------------------------------------------------------- 7| 8| Here is where you can register web routes for your application. These 9| routes are loaded by the RouteServiceProvider within a group which 10| contains the "web" middleware group. Now create something great! 11| 12*/ 13 14Route::get('/', function () { 15 return view('welcome'); 16});

welcome.blade.php

php

1<!doctype html> 2<html lang="{{ str_replace('_', '-', app()->getLocale()) }}"> 3 <head> 4 <meta charset="utf-8"> 5 <meta name="viewport" content="width=device-width, initial-scale=1"> 6 7 <title>Larticles App</title> 8 9 <!-- Fonts --> 10 <link href="https://fonts.googleapis.com/css?family=Nunito:200,600" rel="stylesheet" type="text/css"> 11 </head> 12 <body> 13 <div id="app"> 14 <div class="container"> 15 <articles></articles> 16 </div> 17 </div> 18 <script src="{{ asset('js/app.js')}}"></script> 19 </body> 20</html>

Laravelを使ったことのある方、またはVue.js phpに詳しい方がいましたら
ご確認いただけないでしょうか?

スペルミスかどうかも確認しましたが解決できませんでした。
ちなみにLaravelの環境構築は以下のサイトを参考にしました。
https://techacademy.jp/magazine/11521

bochan2👍を押しています

気になる質問をクリップする

クリップした質問は、後からいつでもMYページで確認できます。

またクリップした質問に回答があった際、通知やメールを受け取ることができます。

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

m.ts10806

2018/12/30 04:41

コードは画像ではなくテキストでマークダウン利用して提示いただけますか? コピペもできないので再現確認やコードのミスが見つけづらいです
Linkey

2019/01/01 05:20

マークダウンでソースコードを記載しました。
guest

回答1

0

welcome.blade.phpにはcsrfがないので自分で追加するか、

<meta name="csrf-token" content="{{ csrf_token() }}">

php artisan make:authでデフォルトのレイアウトを作る。
Laravelはこれがデフォルトのビュー。
https://github.com/laravel/framework/blob/5.7/src/Illuminate/Auth/Console/stubs/make/views/layouts/app.stub

welcomeに書かれてないのはひっかかりやすい罠。

投稿2018/12/30 05:04

kawax

総合スコア10377

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

Linkey

2018/12/31 02:42 編集

回答ありがとうございます。 csrfを追加したところブラウザのコンソールのエラーはなくなりましたが テンプレートは表示されませんでした。何かインストールが必要なものはありますでしょうか? 修正内容は以下です。 welcome.blade.php <!doctype html> <html lang="{{ str_replace('_', '-', app()->getLocale()) }}"> <head> <meta charset="utf-8"> <!-- <meta name="viewport" content="width=device-width, initial-scale=1"> --> <meta name="csrf-token" content="{{ csrf_token() }}"> <title>Larticles App</title> <!-- Fonts --> <link href="https://fonts.googleapis.com/css?family=Nunito:200,600" rel="stylesheet" type="text/css"> </head> <body> <div id="app"> <div class="container"> <articles></articles> </div> </div> <script src="{{ asset('js/app.js')}}"></script> </body> </html>
guest

あなたの回答

tips

太字

斜体

打ち消し線

見出し

引用テキストの挿入

コードの挿入

リンクの挿入

リストの挿入

番号リストの挿入

表の挿入

水平線の挿入

プレビュー

まだベストアンサーが選ばれていません

会員登録して回答してみよう

アカウントをお持ちの方は

15分調べてもわからないことは
teratailで質問しよう!

ただいまの回答率
85.49%

質問をまとめることで
思考を整理して素早く解決

テンプレート機能で
簡単に質問をまとめる

質問する

関連した質問