注意:
有时候使用npm i node-sass -D装不上,这时候,就必须使用 cnpm i node-sass -D
在普通页面中使用render函数渲染组件
在webpack中配置.vue组件页面的解析
运行
cnpm i vue -S将vue安装为运行依赖;运行
cnpm i vue-loader vue-template-compiler -D将解析转换vue的包安装为开发依赖;运行
cnpm i style-loader css-loader -D将解析转换CSS的包安装为开发依赖,因为.vue文件中会写CSS样式;在
webpack.config.js中,添加如下module规则:
1 |
|
- 创建
App.js组件页面:
1 |
|
- 创建
main.js入口文件:
1 |
|
在使用webpack构建的Vue项目中使用模板对象?
- 在
webpack.config.js中添加resolve属性:1
2
3
4
5resolve: {
alias: {
'vue$': 'vue/dist/vue.esm.js'
}
}
ES6中语法使用总结
使用
export default和export导出模块中的成员; 对应ES5中的module.exports和export使用
import ** from **和import '路径'还有import {a, b} from '模块标识'导入其他模块使用箭头函数:
(a, b)=> { return a-b; }
在vue组件页面中,集成vue-router路由模块
- 导入路由模块:
1 |
|
- 安装路由模块:
1 |
|
- 导入需要展示的组件:
1 |
|
- 创建路由对象:
1 |
|
- 将路由对象,挂载到 Vue 实例上:
1 |
|
- 改造App.vue组件,在 template 中,添加
router-link和router-view:
1 |
|
组件中的css作用域问题
1 | <style lang="scss" scoped> |