duandang9434 2019-06-08 10:42
浏览 184

在Symfony 4中集成VueJs,它没有效果

I try to integrate VueJs to Symfony 4.3.

I have installed webpack-encore, vue vue-loader vue-template-compiler and so on.

Everything shows normal.

My os is windows 10. I have installed nodejs and yarn.

    Documents>node -v 
    v12.4.0
    Documents>npm -v
    6.9.0
    Documents>yarn -v
    1.16.0

//webpack.config.js

var Encore = require('@symfony/webpack-encore');

Encore

.setOutputPath('public/build/')

.setPublicPath('/build')

.addEntry('app', './assets/js/app.js')


.enableVueLoader()

.splitEntryChunks()

.enableSingleRuntimeChunk()

.cleanupOutputBeforeBuild()
.enableBuildNotifications()
.enableSourceMaps(!Encore.isProduction())
.enableVersioning(Encore.isProduction())

.configureBabel(() => {}, {
    useBuiltIns: 'usage',
    corejs: 3
})

if (!Encore.isRuntimeEnvironmentConfigured()) {
    Encore.configureRuntimeEnvironment(process.env.NODE_ENV || 'dev');

}

module.exports = Encore.getWebpackConfig();

//app.js

import Vue from "vue";
import App from "./components/App";

console.log('abc');

new Vue({
    el: '#app',
    components: { App },
})

//App.vue

    <template>
        <h2>Welcome to Symfony 4 and vuejs</h2>
    </template>

    <script>
        export default {
        }
    </script>

    <style scoped>

    </style>

//index.html.twig

{% extends 'base.html.twig' %}

{% block title %}Hello HomeController!{% endblock %}

{% block body %}
    <div id="app">
       <App> </App>
    </div>

{% endblock %}

//base.html.twig

<!DOCTYPE html>
    <html>
    <head>
        <meta charset="UTF-8">
        <title>{% block title %}Welcome!{% endblock %}</title>
        {% block stylesheets %}{% endblock %}
        <script src="{{ asset('build/app.js') }}"></script>
    </head>
    <body>
        {% block body %}{% endblock %}
        {% block javascripts %}{% endblock %}
    </body>
    </html>

//HomeController.php

    class HomeController extends AbstractController
    {
        /**
         * @Route("/home", name="home")
         * @return Response
         */
        public function index()
        {
            return $this->render('home/index.html.twig', [
                'controller_name' => 'HomeController',
            ]);
        }
    }

When I make the server run,all correct,not excetipn but noting shows.

D:\symfonyvue>npm run dev-server

> @ dev-server D:\symfonyvue
> encore dev-server

Running webpack-dev-server ...

 DONE  Compiled successfully in 3026ms
php bin/console server:run


 [OK] Server listening on http://127.0.0.1:8001


 // Quit the server with CONTROL-C.

visite the http://127.0.0.1:8000/home


<!DOCTYPE html>
<html>
    <head>
        <meta charset="UTF-8">
        <title>Hello HomeController!</title>
                <script src="http://localhost:8080/build/app.js"></script>
    </head>
    <body>
            <div id="app">
       <App> </App>
    </div>
  • 写回答

0条回答

    报告相同问题?

    悬赏问题

    • ¥15 matlab实现基于主成分变换的图像融合。
    • ¥15 对于相关问题的求解与代码
    • ¥15 ubuntu子系统密码忘记
    • ¥15 信号傅里叶变换在matlab上遇到的小问题请求帮助
    • ¥15 保护模式-系统加载-段寄存器
    • ¥15 电脑桌面设定一个区域禁止鼠标操作
    • ¥15 求NPF226060磁芯的详细资料
    • ¥15 使用R语言marginaleffects包进行边际效应图绘制
    • ¥20 usb设备兼容性问题
    • ¥15 错误(10048): “调用exui内部功能”库命令的参数“参数4”不能接受空数据。怎么解决啊