Fat's 杂物屋

  • 首页
  • 关于我
Fat's 杂物屋
python语言工作自动化技术
  1. 首页
  2. 网站构建
  3. 正文

Laravel中安装Bootstrap-vue时提示You are using the runtime-only build错误

2021年7月12日 2732点热度 0人点赞 0条评论

根据Bootstrap-vue的文档,用npm安装。

//在系统终端中:
npm install vue bootstrap-vue bootstrap

然后在程序入口的app.js中引入。

// 在程序入口的app.js

import Vue from 'vue'
import { BootstrapVue, IconsPlugin } from 'bootstrap-vue'

// Install BootstrapVue
Vue.use(BootstrapVue)
// Optionally install the BootstrapVue icon components plugin
Vue.use(IconsPlugin)

然后用Laravel框架自带的Mix插件打包前端资源,此时一切正常。

//在系统终端中:
npm run dev

但是网页中如果用<script src="/js/app.js"></script>导入js文件时,浏览器就会报错:

[Vue warn]: You are using the runtime-only build of Vue where the template compiler is not available. Either pre-compile the templates into render functions, or use the compiler-included build.

(found in <Root>)

原因是,node_modules里的Vue模块的package.json里面,设定了默认打包文件是“dist/vue.runtime.esm.js”的。

 

解决方法一:

修改Vue的package.json文件,修改默认打包文件:

  "module": "dist/vue.runtime.esm.js"
改为↓
  "module": "dist/vue.js"(如果在开发环境)
  "module": "dist/vue.min.js"(如果在生产环境)

解决方法二:

在Mix打包前端资源时,为import Vue from 'vue'指定别名:

=//在Laravel项目根目录的webpack.mix.js里:

const path = require('path');

mix.alias({
    vue$: path.join(__dirname, 'node_modules/vue/dist/vue.js')
});

 

这样就可以正常在网页中使用<script src="/js/app.js"></script>了。

 

 

本作品采用 知识共享署名 4.0 国际许可协议 进行许可
标签: Bootstrap-Vue Laravel Vue
最后更新:2021年7月12日

fat

我只是一只海獭。

点赞
< 上一篇
下一篇 >

文章评论

razz evil exclaim smile redface biggrin eek confused idea lol mad twisted rolleyes wink cool arrow neutral cry mrgreen drooling persevering
取消回复

fat

我只是一只海獭。

分类
  • python / 5篇
  • 数码硬件 / 5篇
  • 杂谈 / 1篇
  • 网站构建 / 13篇
最新 热点 随机
最新 热点 随机
laravel 11.x 及 Vue3安装,作为SPA单网页应用框架 ubuntu中部署基于Gradio框架的AI demo(nginx反向代理) ubuntu构建LNMP环境和安装WordPress ubuntu使用flask错误:ImportError: libGL.so.1: cannot open shared object file: No such file or directory解决办法 uWSGI提示错误uwsgi: unrecognized option '--wsgi-file'解决办法 Laravel优化SQL分页查询语句
ubuntu使用flask错误:ImportError: libGL.so.1: cannot open shared object file: No such file or directory解决办法 Gen10 Plus服务器 ESXi 7.0系统搭建NAS+HTPC —— 篇3:直通显卡 laravel 11.x 及 Vue3安装,作为SPA单网页应用框架 Laravel报错Controller不存在 Target class [App\\Http\\Controllers\\API\\***Controller] does not exist Laravel中安装Bootstrap-vue时提示You are using the runtime-only build错误 Gen10 Plus服务器 ESXi 7.0系统搭建NAS+HTPC —— 篇2:直通USB无线键鼠

COPYRIGHT © 2023 Fat's 杂物屋. ALL RIGHTS RESERVED.

Theme Kratos Made By Seaton Jiang

粤ICP备2020113573号