(一)模块与组件、模块化与组件化
1.模块
- 理解:向外提供特定功能的 js 程序,一般就是一个 js 文件
- 为什么:js 文件很多很复杂
- 作用:复用 js,简化 js 的编写,提高 js 运行效率
2.组件
- 理解:用来实现局部(特定)功能效果的代码集合(html/css/js/image/...)
- 为什么:一个界面的功能很复杂
- 作用:复用编码,简化项目编码,提高项目运行效率
3.模块化
小于 1 分钟
Vue.extend(options)
创建new Vue(options)
时传入的那个 options 几乎一样npm install -g @vue/cli
<h1 ref="xxx"></h1>
<!-- 或者 -->
<School ref="xxx"></School>
<Demo name="xxx" />
export const mixin = {
data(){...},
methods(){...},
...
};
对象.install = function(Vue, options) {
// 1.添加全局过滤器
Vue.filter(...);
// 2.添加全局指令
Vue.directive(...);
// 3.配置全局混入(合)
Vue.mixin(...);
// 4.添加实例方法
Vue.prototype.$myMethod = function() {...}
Vue.prototype.$myProperty = xxx;
}
<style scoped>
.....
</style>