详解vue-cli快速构建项目以及引入bootstrap、jq


Posted in Javascript onMay 26, 2017

vue-cli脚手架工具快速构建项目架构:

。。首先默认了有已经安装了node。。。

 npm install -g vue-cli                   全局安装vue-cli

 vue init webpack cnm                  生成项目名为cnm的的项目模板,cnm自定义

npm install                                   到cnm文件夹中打开Git bash或者命令窗口初始化安装依赖

此时文件夹目录应该是这样

详解vue-cli快速构建项目以及引入bootstrap、jq

然后输入npm run dev。。不出意外浏览器会自动弹出一个欢迎页面,如果不自动弹出就打开http://localhost:8080

详解vue-cli快速构建项目以及引入bootstrap、jq

到这里就可以在对应的文件中修改代码开发项目了。。。但是如果要引入一些插件或者框架怎么办呢?

引入jq:

输入 npm install jQuery --save-dev      用npm下载jq依赖、

找到build文件夹下的webpack.base.conf.js文件打开,修改配置:

1、加入webpack对象:

var webpack=require('webpack');

2、在module.exports里面加入:

plugins: [ 
 new webpack.ProvidePlugin({ 
  $:"jquery", 
  jQuery:"jquery", 
  "windows.jQuery":"jquery" 
 }) 
]

3、在入口文件main.js中加入

import $ from 'jquery'

全局引入jq

引入bootstrap:

1、修改webpack.base.conf.js文件:

alias: { 
   'vue$': 'vue/dist/vue.esm.js', 
   '@': resolve('src'), 
   'assets': path.resolve(__dirname, '../src/assets'), 
   'jquery': "jquery/src/jquery" 
  }

2、在入口文件main.js中加入:

import './assets/css/bootstrap.min.css' 
import './assets/js/bootstrap.min'

3、在assets文件目录中拷贝bootstrap各种文件

详解vue-cli快速构建项目以及引入bootstrap、jq

试试bootstrap引入成功没:

打开hello.vue文件

替换组件模板

<template> 
 <nav class="navbar navbar-default" role="navigation"> 
  <div class="container-fluid"> 
   <!-- Brand and toggle get grouped for better mobile display --> 
   <div class="navbar-header"> 
    <button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target="#bs-example-navbar-collapse-1"> 
     <span class="sr-only">Toggle navigation</span> 
     <span class="icon-bar"></span> 
     <span class="icon-bar"></span> 
     <span class="icon-bar"></span> 
    </button> 
    <a class="navbar-brand" href="#" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" >{{ msg }}</a> 
   </div> 
 
   <!-- Collect the nav links, forms, and other content for toggling --> 
   <div class="collapse navbar-collapse" id="bs-example-navbar-collapse-1"> 
    <ul class="nav navbar-nav"> 
     <li class="active"><a href="#" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" >Link</a></li> 
     <li><a href="#" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" >Link</a></li> 
     <li class="dropdown"> 
      <a href="#" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" class="dropdown-toggle" data-toggle="dropdown">Dropdown <span class="caret"></span></a> 
      <ul class="dropdown-menu" role="menu"> 
       <li><a href="#" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" >Action</a></li> 
       <li><a href="#" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" >Another action</a></li> 
       <li><a href="#" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" >Something else here</a></li> 
       <li class="divider"></li> 
       <li><a href="#" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" >Separated link</a></li> 
       <li class="divider"></li> 
       <li><a href="#" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" >One more separated link</a></li> 
      </ul> 
     </li> 
    </ul> 
    <form class="navbar-form navbar-left" role="search"> 
     <div class="form-group"> 
      <input type="text" class="form-control" placeholder="Search"> 
     </div> 
     <button type="submit" class="btn btn-default">Submit</button> 
    </form> 
    <ul class="nav navbar-nav navbar-right"> 
     <li><a href="#" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" >Link</a></li> 
     <li class="dropdown"> 
      <a href="#" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" class="dropdown-toggle" data-toggle="dropdown">Dropdown <span class="caret"></span></a> 
      <ul class="dropdown-menu" role="menu"> 
       <li><a href="#" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" >Action</a></li> 
       <li><a href="#" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" >Another action</a></li> 
       <li><a href="#" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" >Something else here</a></li> 
       <li class="divider"></li> 
       <li><a href="#" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" >Separated link</a></li> 
      </ul> 
     </li> 
    </ul> 
   </div><!-- /.navbar-collapse --> 
  </div><!-- /.container-fluid --> 
 </nav> 
</template>

如果引入成功

详解vue-cli快速构建项目以及引入bootstrap、jq

以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持三水点靠木。

Javascript 相关文章推荐
延时重复执行函数 lLoopRun.js
May 08 Javascript
JavaScript获取/更改文本框的值的实例代码
Aug 02 Javascript
基于jQuery.Hz2Py.js插件实现的汉字转拼音特效
May 07 Javascript
JavaScript编程中的Promise使用大全
Jul 28 Javascript
Bootstrap安装环境配置教程分享
May 27 Javascript
gulp-htmlmin压缩html的gulp插件实例代码
Jun 06 Javascript
利用imgareaselect辅助后台实现图片上传裁剪
Mar 02 Javascript
Vue动态实现评分效果
May 24 Javascript
微信小程序 input输入及动态设置按钮的实现
Oct 27 Javascript
浅谈node中的cluster集群
Jun 02 Javascript
vue2.0 下拉框默认标题设置方法
Aug 22 Javascript
mui js控制开关状态、修改switch开关的值方法
Sep 03 Javascript
基于layer.js实现收货地址弹框选择然后返回相应的地址信息
May 26 #Javascript
jQuery导航条固定定位效果实例代码
May 26 #jQuery
mongoose中利用populate处理嵌套的方法
May 26 #Javascript
Angularjs修改密码的实例代码
May 26 #Javascript
详解vue.js的devtools安装
May 26 #Javascript
详解Vue.js基于$.ajax获取数据并与组件的data绑定
May 26 #Javascript
vue.js获取数据库数据实例代码
May 26 #Javascript
You might like
需要发散思维学习PHP
2009/06/29 PHP
利用PHP内置SERVER开启web服务(本地开发使用)
2020/01/22 PHP
javascript iframe中打开文件,并检测iframe存在否
2008/12/28 Javascript
JavaScript isArray()函数判断对象类型的种种方法
2010/10/11 Javascript
基于OL2实现百度地图ABCD marker的效果
2015/10/01 Javascript
Jquery ajax基础教程
2015/11/20 Javascript
基于jQuery实现音乐播放试听列表
2016/04/14 Javascript
基于jQuery下拉选择框插件支持单选多选功能代码
2016/06/07 Javascript
JS调用某段SQL语句的方法
2016/10/20 Javascript
12 款 JS 代码测试必备工具(翻译)
2016/12/13 Javascript
详解vue express启动数据服务
2017/07/05 Javascript
js数字滑动时钟的简单实现(示例讲解)
2017/08/14 Javascript
angular4实现tab栏切换的方法示例
2017/10/21 Javascript
js数组常用最重要的方法
2018/02/04 Javascript
使用Vue.js 和Chart.js制作绚丽多彩的图表
2019/06/15 Javascript
深入浅出vue图片路径的实现
2019/09/04 Javascript
[01:09:20]NB vs NAVI Supermajor小组赛A组 BO3 第二场 6.2
2018/06/03 DOTA
[01:28:24]NAVI vs VG Supermajor 败者组 BO3 第三场 6.5
2018/06/06 DOTA
django创建自定义模板处理器的实例详解
2017/08/14 Python
不同版本中Python matplotlib.pyplot.draw()界面绘制异常问题的解决
2017/09/24 Python
python 遍历目录(包括子目录)下所有文件的实例
2018/07/11 Python
Python判断变量名是否合法的方法示例
2019/01/28 Python
详解DeBug Python神级工具PySnooper
2019/07/03 Python
opencv3/python 鼠标响应操作详解
2019/12/11 Python
html5 Canvas画图教程(6)—canvas里画曲线之arcTo方法
2013/01/09 HTML / CSS
canvas线条的属性详解
2018/03/27 HTML / CSS
极度干燥澳大利亚官方网站:Superdry澳大利亚
2019/03/28 全球购物
大学军训感言800字
2014/02/27 职场文书
法人授权委托书格式
2014/04/08 职场文书
企业宣传策划方案
2014/05/29 职场文书
2015年青年志愿者工作总结
2015/05/20 职场文书
大学生党课感想
2015/08/11 职场文书
安全伴我行主题班会
2015/08/13 职场文书
2019通用版导游词范本!
2019/08/07 职场文书
MySQL的Query Cache图文详解
2021/07/01 MySQL
MySql数据库 查询时间序列间隔
2022/05/11 MySQL