第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

當我將 jquery 添加到我的網(wǎng)站時,我的 JS 不起作用

當我將 jquery 添加到我的網(wǎng)站時,我的 JS 不起作用

有只小跳蛙 2021-09-30 16:46:00
我正在 Symfony 中用 encore 和 yarn 做一個腳本 JS,當我不使用 jquery 并且從不需要他時,我的 JS 工作正常。但是目前我添加了 jquery,const $ = require('jquery')例如我的腳本不起作用并且我沒有收到錯誤消息。我嘗試評論.enableSingleRuntimeChunk(),使用 CDN 添加 jquery,嘗試另一個項目。沒變化。//base.html.twig{% block javascripts %}            <script src="{{ asset('build/runtime.js') }}"></script>            <script src="{{ asset('build/app.js') }}" type="text/javascript"></script>{% endblock %}// Need jQuery? Install it with "yarn add jquery", then uncomment to require it.const $ = require('jquery');console.log('hello');Encore    // directory where compiled assets will be stored    .setOutputPath('public/build/')    .copyFiles({        from: './assets/images'    })    // public path used by the web server to access the output path    .setPublicPath('/build')    // only needed for CDN's or sub-directory deploy    //.setManifestKeyPrefix('build/')    /*     * ENTRY CONFIG     *     * Add 1 entry for each "page" of your app     * (including one that's included on every page - e.g. "app")     *     * Each entry will result in one JavaScript file (e.g. app.js)     * and one CSS file (e.g. app.fontawesome) if your JavaScript imports CSS.     */    .addEntry('app', './assets/js/app.js')    .addEntry('main', './assets/js/main.js')    //.addEntry('page2', './assets/js/page2.js')    // When enabled, Webpack "splits" your files into smaller pieces for greater optimization.    .splitEntryChunks()    // will require an extra script tag for runtime.js    // but, you probably want this, unless you're building a single-page app    .enableSingleRuntimeChunk()
查看完整描述

1 回答

?
UYOU

TA貢獻1878條經(jīng)驗 獲得超4個贊

在 webpack.config.js 中嘗試使用:


.autoProvidejQuery()

取消注釋(如果您已發(fā)表評論)


.enableSingleRuntimeChunk()

并刪除


.autoProvidejQuery({

    $: 'jquery',

    jQuery: 'jquery',

    'window.jQuery': 'jquery'

})

在 app.js 中注釋//const $ = require('jquery');并使用 jquery


在 base.html.twig 中使用


{% block javascripts %}

       {{ encore_entry_script_tags('app') }}

{% endblock %}

最后運行yarn encore dev(對于 dev env)或 yarn encore prod(對于 prod env)并重新加載頁面


查看完整回答
反對 回復(fù) 2021-09-30
  • 1 回答
  • 0 關(guān)注
  • 261 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動學(xué)習伙伴

公眾號

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號