You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

首次在Laravel中使用Vue.js无报错但组件不渲染问题求助

Troubleshooting Blank Page with Vue Component in Laravel

Hey there! It's super common to hit this kind of snag when getting started with Vue in Laravel—no errors, but your component just won't show up. Let's walk through the most likely fixes step by step:

1. Make Sure Your Assets Are Compiled

Laravel uses Mix to bundle Vue components into your app.js file. If you haven't compiled your resources yet, your component code isn't actually in the file the browser is loading.

  • First, install dependencies if you haven't:
    npm install
    
  • Then compile your assets:
    npm run dev
    
    Or use npm run watch to auto-compile when you make changes to Vue files.
  • Double-check that public/js/app.js exists after compiling—this is where your bundled code lives.

2. Verify Component Paths Are Correct

Your app.js is trying to load ./components/Favourup.vue—make sure the file is actually in resources/js/components/Favourup.vue. A tiny typo in the filename or folder structure (like uppercase vs lowercase) will break this silently.

3. Check Vue Version Compatibility

This is a big one for newer Laravel versions:

  • Laravel 9 and above default to Vue 3, but your app.js code uses Vue 2 syntax (Vue.component() and new Vue()). These don't work with Vue 3.
  • To fix this, update your app.js to use Vue 3's syntax:
    import { createApp } from 'vue';
    import Favourup from './components/Favourup.vue';
    
    const app = createApp({});
    app.component('favourup', Favourup);
    app.mount('#app');
    
  • If you want to stick with Vue 2 instead, install the right packages:
    npm install vue@2 vue-template-compiler
    
    Then your original app.js code will work.

4. Ensure app.js Is Loading Correctly

  • Open your browser's developer tools (F12), go to the Network tab, and refresh the page. Look for app.js—if it shows a 404 error, your path is wrong.
  • Replace {{ asset('js/app.js') }} in your blade file with {{ mix('js/app.js') }}. Mix handles versioning and ensures the correct path is used, especially if you've run npm run production.

5. Double-Check Your Blade Structure

Your blade code looks right, but just to be safe:

  • Make sure there's no CSS hiding the component (like display: none on the #app div or the component itself).
  • Confirm the <script> tag for app.js is placed after the #app div—your code already does this, which is correct, since Vue needs to find the element to mount to.

Try these steps one by one, and you should see that "FavourUp" text pop up in no time!

内容的提问来源于stack exchange,提问作者S123l2000

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.08 08:37:50