Javascript 如何正确使用Laravel和Vue?

Javascript 如何正确使用Laravel和Vue?,javascript,php,laravel,vue.js,Javascript,Php,Laravel,Vue.js,请是使用Laravel+Vue的新手。我已注册一个组件,但它无法在我的刀片模板中显示内容。请告诉我如何在Laravel和Vue中正确执行此操作,我需要帮助 代码如下 layout.app {{config('app.name','Laravel')} @客人 @if(Route::has('register')) @恩迪夫 @否则 @csrf @终客 @产量(‘含量’) 欢迎使用.blade.php @extends('layouts.app')) @节(“内容”) Vu

请是使用Laravel+Vue的新手。我已注册一个组件,但它无法在我的刀片模板中显示内容。请告诉我如何在Laravel和Vue中正确执行此操作,我需要帮助

代码如下 layout.app


{{config('app.name','Laravel')}
    @客人
  • @if(Route::has('register'))
  • @恩迪夫 @否则
  • @csrf
  • @终客
@产量(‘含量’)
欢迎使用.blade.php

@extends('layouts.app'))
@节(“内容”)
Vue Js Todo应用程序
@端部
app.js

/**
*首先,我们将加载该项目的所有JavaScript依赖项
*包括Vue和其他库。这是一个很好的起点
*使用Vue和Laravel构建健壮、功能强大的web应用程序。
*/
从“Vue”导入Vue;
需要('./引导');
window.Vue=require('Vue');
/**
*以下代码块可用于自动注册您的
*Vue组件。它将递归扫描此目录以查找Vue
*组件,并使用其“basename”自动注册它们。
*
*例如../components/ExampleComponent.vue->
*/
//const files=require.context('./',true,/\.vue$/i)
//files.keys().map(key=>Vue.component(key.split('/').pop().split('.')[0],files(key.default))
组件('example-component',require('./components/ExampleComponent.Vue')。默认值);
组件('articles',require('./components/articles.Vue')。默认值);
/**
*接下来,我们将创建一个新的Vue应用程序实例并将其附加到
*这一页。然后,您可以开始向该应用程序添加组件
*或者定制JavaScript框架以满足您的独特需求。
*/
const app=新的Vue({
el:“#应用程序”,
});
myArticles.Vue中的内容


按钮

我需要帮助。这对我不起作用。

看起来一切都做对了!您是否在进行更改后构建了更改

如果没有,请使用
npm run prod
,这将编译public app.css和app.js文件中的javascript和scss资产。您已将其包含在刀片布局文件中

如果仍然无法使用,请共享您的
webpack.mix.js
文件

<!doctype html>
<html lang="{{ str_replace('_', '-', app()->getLocale()) }}">
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1">

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

    <title>{{ config('app.name', 'Laravel') }}</title>

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

    <!-- Fonts -->
    <link rel="dns-prefetch" href="//fonts.gstatic.com">
    <link href="https://fonts.googleapis.com/css?family=Nunito" rel="stylesheet">

    <!-- Styles -->
    <link href="{{ asset('css/app.css') }}" rel="stylesheet">
</head>
<body>
    <div id="app">
        <nav class="navbar navbar-expand-md navbar-light bg-white shadow-sm">
            <div class="container">
                <a class="navbar-brand" href="{{ url('/') }}">
                    {{ config('app.name', 'Laravel') }}
                </a>
                <button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#navbarSupportedContent" aria-controls="navbarSupportedContent" aria-expanded="false" aria-label="{{ __('Toggle navigation') }}">
                    <span class="navbar-toggler-icon"></span>
                </button>

                <div class="collapse navbar-collapse" id="navbarSupportedContent">
                    <!-- Left Side Of Navbar -->
                    <ul class="navbar-nav mr-auto">

                    </ul>

                    <!-- Right Side Of Navbar -->
                    <ul class="navbar-nav ml-auto">
                        <!-- Authentication Links -->
                        @guest
                            <li class="nav-item">
                                <a class="nav-link" href="{{ route('login') }}">{{ __('Login') }}</a>
                            </li>
                            @if (Route::has('register'))
                                <li class="nav-item">
                                    <a class="nav-link" href="{{ route('register') }}">{{ __('Register') }}</a>
                                </li>
                            @endif
                        @else
                            <li class="nav-item dropdown">
                                <a id="navbarDropdown" class="nav-link dropdown-toggle" href="#" role="button" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false" v-pre>
                                    {{ Auth::user()->name }}
                                </a>

                                <div class="dropdown-menu dropdown-menu-right" aria-labelledby="navbarDropdown">
                                    <a class="dropdown-item" href="{{ route('logout') }}"
                                       onclick="event.preventDefault();
                                                     document.getElementById('logout-form').submit();">
                                        {{ __('Logout') }}
                                    </a>

                                    <form id="logout-form" action="{{ route('logout') }}" method="POST" class="d-none">
                                        @csrf
                                    </form>
                                </div>
                            </li>
                        @endguest
                    </ul>
                </div>
            </div>
        </nav>

        <main class="py-4">
            @yield('content')
        </main>
    </div>
</body>
</html>

@extends('layouts.app')
@section('content')

<div>Vue Js Todo App</div>
<articles></articles>

@endsection
/**
 * First we will load all of this project's JavaScript dependencies which
 * includes Vue and other libraries. It is a great starting point when
 * building robust, powerful web applications using Vue and Laravel.
 */

import Vue from 'vue';
require('./bootstrap');

window.Vue = require('vue');

/**
 * The following block of code may be used to automatically register your
 * Vue components. It will recursively scan this directory for the Vue
 * components and automatically register them with their "basename".
 *
 * Eg. ./components/ExampleComponent.vue -> <example-component></example-component>
 */

// const files = require.context('./', true, /\.vue$/i)
// files.keys().map(key => Vue.component(key.split('/').pop().split('.')[0], files(key).default))

Vue.component('example-component', require('./components/ExampleComponent.vue').default);
Vue.component('articles', require('./components/Articles.vue').default);

/**
 * Next, we will create a fresh Vue application instance and attach it to
 * the page. Then, you may begin adding components to this application
 * or customize the JavaScript scaffolding to fit your unique needs.
 */

const app = new Vue({
    el: '#app',
});
<template>
    <div>
        <form>
            <div class="input-group mb-3">
            <input type="text" class="form-control" placeholder="Recipient's username" aria-label="Recipient's username" aria-describedby="button-addon2">
            <div class="input-group-append">
                <button class="btn btn-outline-secondary" type="button" id="button-addon2">Button</button>
            </div>
            </div>
        </form>
    </div>
</template>