簡體   English   中英

Vuejs 組件未顯示在我的 Laravel 刀片中

[英]Vuejs component not showing in my laravel blade

我正在使用 laravel 和 vue,但無法將組件加載到刀片頁面中。 顯示為空。

我嘗試了很多解決方案,但都不起作用。

歡迎刀片

<!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() }}">
    <script>
        window.Laravel = { csrfToken: '{{ csrf_token() }}' }
    </script>
    <title>App</title>

    <!-- Fonts -->
    <link href="https://fonts.googleapis.com/css? family=Nunito:200,600" rel="stylesheet">  
</head>
<body>
    <script type="text/javascripts" src="js/app.js"></script>
        <div id ="app">
            <div class="container">
                <articles></articles>
            </div> 
        </div>    
</body>
</html>

文章.vue

<template>
    <div>
        <h2>Articles</h2>
    </div>
</template>

應用程序.js

/**
 * 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.
 */

require('./bootstrap');

import articles from './components/Articles'
    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));


/**
 * 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.
 */

Vue.component('articles', require('./components/Articles.vue'));

const app = new Vue({
    el: '#app',
});

作曲家.json

{
    "name": "laravel/laravel",
    "type": "project",
    "description": "The Laravel Framework.",
    "keywords": [
        "framework",
        "laravel"
    ],
    "license": "MIT",
    "require": {
        "php": "^7.1.3",
        "fideloper/proxy": "^4.0",
        "laravel/framework": "5.8.*",
        "laravel/tinker": "^1.0"
    },
    "require-dev": {
        "beyondcode/laravel-dump-server": "^1.0",
        "filp/whoops": "^2.0",
        "fzaninotto/faker": "^1.4",
        "mockery/mockery": "^1.0",
        "nunomaduro/collision": "^3.0",
        "phpunit/phpunit": "^7.5"
    },
    "config": {
        "optimize-autoloader": true,
        "preferred-install": "dist",
        "sort-packages": true
    },
    "extra": {
        "laravel": {
            "dont-discover": []
        }
    },
    "autoload": {
        "psr-4": {
            "App\\": "app/"
        },
        "classmap": [
            "database/seeds",
            "database/factories"
        ]
    },
    "autoload-dev": {
        "psr-4": {
            "Tests\\": "tests/"
        }
    },
    "minimum-stability": "dev",
    "prefer-stable": true,
    "scripts": {
        "post-autoload-dump": [
            "Illuminate\\Foundation\\ComposerScripts::postAutoloadDump",
            "@php artisan package:discover --ansi"
        ],
        "post-root-package-install": [
            "@php -r \"file_exists('.env') || copy('.env.example', '.env');\""
        ],
        "post-create-project-cmd": [
            "@php artisan key:generate --ansi"
        ]
    }
}

我期待將文章視為 h2,但它什么也沒顯示,當我檢查元素時,我看到了這個錯誤

“未捕獲的類型錯誤:Vue.components 不是函數”。

任何幫助將不勝感激。

npm install vuejs 包必須像這樣顯示

在此處輸入圖片說明

然后,在你的 app.js 中

Vue.component('articles', require('./components/Articles.vue').default);
const app = {
init() {
    this.setupVue();
},

setupVue() {
    new Vue({
        el: '#app',
    });
}
};
app.init()

在 laravel 7 項目上從laravel-mix 5.0.9更新到laravel-mix 6.0.11 ,它開始在 vue 編譯視圖上看到此錯誤。 我改變調用Vue包:

使用import Vue from 'vue'而不是window.Vue = require("vue"); 為我工作。

Vue.component is not a function告訴我我沒有進行正確的VueJs調用,這就是為什么找不到component函數的原因。 這個新的導入解決了這個問題。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM