vue-cli · Failed to download repo vuejs-templates/webpack-simple: unable to verify the first certificate:
1.在https://github.com/vuejs-templates/下载相应的模板
2.把解压出的文件夹放在 C:\Users\当前用户名.vue-templates
没有就新建一个 .vue-templates
新建失败的话,记得要在后面加一个点 .vue-templates.
3.安装了vue-cli之后进行初始化项目 vue init webpack-simple project --offline
/*****************************************************************************/
引入import ‘element-ui/lib/theme-chalk/index.css’ 报错?./node_modules/element-ui/lib/theme-chalk/fonts/element-icons.ttf
Module parse failed: Unexpected character ‘’ (1:0)
You may need an appropriate loader to handle this file type.
解决方法:在webpack.config.js里的rules里面加上
{ test: /.(eot|woff|ttf)$/, loader: ‘file-loader’ }
/******************************************************************************/
element环境搭建:
1、在https://github.com/vuejs-templates/下载相应的模板(webpack-simple)
2、把解压出的文件夹放在 C:\Users\当前用户名.vue-templates 。没有就新建一个 .vue-templates
3、vue init webpack-simple project --offline
4、cd project
5、npm init --force
6、npm install
7、npm run dev(此时vue-cli脚手架就搭建好了)
8、npm install element-ui -S // 安装element
9、npm install router
10、在webpack.config.js里的rules加上:{ test: /.(eot|woff|ttf)$/, loader: ‘file-loader’ }
11、修改main.js:
import Vue from 'vue'
import App from './App.vue'
import router from 'router'
import ElementUI from 'element-ui'
import 'element-ui/lib/theme-chalk/index.css'
Vue.config.productionTip = false
Vue.use(ElementUI)
new Vue({
el: '#app',
router,
template: '<App/>',
components: {App}
})
12、再次执行npm run dev,成功。
成功之后,进入element官网:http://element.eleme.io/#/zh-CN/component/transition。
点击"内置过度动画",选择一个例子,将源码拷贝,直接覆盖项目中的App.vue文件的代码,此时可以直接在页面中看到效果。
App.vue文件例子:
<template>
<div>
<el-radio v-model="radio" label="1">备选项</el-radio>
<el-radio v-model="radio" label="2">备选项</el-radio>
<el-checkbox v-model="checked">备选项</el-checkbox>
</div>
</template>
<script>
export default {
data () {
return {
radio: '2',
checked: true
};
}
}
</script>
<style>
.el-header {
background-color: #B3C0D1;
color: #333;
line-height: 60px;
}
.el-aside {
color: #333;
}
</style>
若要添加官网其他的例子,只需要把代码拷贝到App.vue文件的template节点里面。如果要添加多个控件,需要将控件代码加到template的同一个div里面,否则会报错:Component template should contain exactly one root element. If you are using v-if on multiple elements, use v-else-if to chain them instead。
在index.html文件中:
<div id="app"></div>
<script src="/dist/build.js"></script>
上面2行代码即是引入了element打包后的文件(注意:<div id="app"></div>
这个不能删除,否则会使element引入的打包文件失效),可以在index.html文件中调换位置来放置在body的不同位置中。例如:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>element-demo</title>
</head>
<body>
<div class="container" style="margin-top: 20px;">
<input type="text" placeholder="SunXiang">
<button>TestBtn</button>
</div>
<div style="margin-top: 20px;">
<div id="app" ></div>
<script src="/dist/build.js"></script>
</div>
<div class="container" style="margin-top: 20px;">
<input type="text" placeholder="SunXiang">
<button>TestBtn</button>
</div>
</body>
</html>
</body>
</html>
显示结果如下: