在laravel 5.4混合上添加jQuery [英] Add jQuery on laravel 5.4 mix

查看:77
本文介绍了在laravel 5.4混合上添加jQuery的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经熟悉laravel 5.1 mix(elixir),最近我决定测试laravel 5.4 mix.

I'm already familiar with laravel 5.1 mix (elixir), and recently I decided to test laravel 5.4 mix.

我在供应商文件中混合了我的库.

I mixed my libs on vendors files.

mix
.styles([
    './node_modules/bootstrap/dist/css/bootstrap.css',
    './node_modules/font-awesome/css/font-awesome.css'
], 'public/css/vendor.css')
.js([
    './node_modules/jquery/dist/jquery.js',
    './node_modules/bootstrap/dist/js/bootstrap.js',
], 'public/js/vendor.js')
.disableNotifications()
.version();

并在我的页面上包括了供应商.

And included vendor on my page.

<script src="{{ mix('js/vendor.js') }}" type="text/javascript" charset="utf-8" async defer></script>

但是,当我想使用jQuery时,我在下面的图片上遇到此错误.以前,在laravel 5.1中,我正是这样做的.

But, when I want use jQuery I have this error on image below. Before, in the laravel 5.1 I did exactly that way.

我该怎么办?

推荐答案

只需在assets/js/bootstrap.js文件中取消注释此行:

Just uncomment this line in your assets/js/bootstrap.js file:

window.$ = window.jQuery = require('jquery');

并确保在您的assets/js/app.js中需要这样的引导文件:

And make sure to require the bootstrap file in your assets/js/app.js like this:

require('./bootstrap');

这篇关于在laravel 5.4混合上添加jQuery的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆