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条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥30 这是哪个作者做的宝宝起名网站
    • ¥60 版本过低apk如何修改可以兼容新的安卓系统
    • ¥25 由IPR导致的DRIVER_POWER_STATE_FAILURE蓝屏
    • ¥50 有数据,怎么建立模型求影响全要素生产率的因素
    • ¥50 有数据,怎么用matlab求全要素生产率
    • ¥15 TI的insta-spin例程
    • ¥15 完成下列问题完成下列问题
    • ¥15 C#算法问题, 不知道怎么处理这个数据的转换
    • ¥15 YoloV5 第三方库的版本对照问题
    • ¥15 请完成下列相关问题!