全部HTML元素能够看做盒子,在CSS中,"box model"这一术语是用来设计和布局时使用。CSS盒模型本质上是一个盒子,封装周围的HTML元素,它包括:边距,边框,填充,和实际内容javascript
JavaScript是一种弱类型语言html
6种原始类型前端
*可使用typeof 判断数据类型,数组以及null都属于Object
*Object属于引用类型,具备:constructor、hasOwnProperty、isPropertyOf、propertyIsEnumerable等方法。vue
对象的属性html5
修改默认特性使用defineProperty(),访问器属性不能直接定义,只能调该用方法。java
对象的建立git
构造函数:正则表达式
function Person(name, age ,job){ this.name = name; this.age = age; this.job = job; this.sayName = function(){ console.log(this.name); } } let person1 = new Person("name", 20, "job");
原型模式:数组
function Person(){ } Person.prototype.name = "name"; Person.prototype.age = 20; Person.prototype.job = "job"; Person.prototype.sayName = function(){ console.log(this.name); } let person1 = new Person();
JavaScript经常使用的字符串操做浏览器
JavaScript经常使用的数组操做
- concat - 合并数组 - push、pop - 分别为添加、删除元素,堆栈形式 - unshift、shift - 添加、删除元素,队列形式 - reverse - 反转 - sort() - 排序, arr.sort(function(a,b){return a-b;} 输入比较函数 - slice、splice - 删除,参数为起始位置和个数,slice不改变原素组,返回新数组,splice会改变原素组,返回被删除的数组。 - substring、substr - 截取数组,相似于上面字符串中的这两个方法。
为了避免让分块的代码污染全局,以及更好地使用别人的代码因此产生了JavaScript模块化的需求
可使用当即执行函数
var params = 'test'; var module = (function(params){ var mod = function(){ //... }; return {mod: mod}; })(params);
外部不能直接访问模块内部的变量,传入外部变量后,在内部改变它的值也不影响全局。
特性
如下写法涉及到了全部样式以及类名的绑定方式,不详细说明了
:style=“[item.a,item.b]” :style="{width:item.value+'px'}" :style="{color: activeColor, fontSize: fontSize + 'px' }" :style="item.titlefont" :style="a<0? 'color:red':'color:black'" :style="item.choosetype==3?{width:ul_width+'px'}:''"
:class="{a:item.x==1}" :class="[b ,{a:item.x==1}]" :class="{a:item.x==1, b:item.x==2}" <div v-bind:class="[isActive ? activeClass : '', errorClass]">
遇到的问题以及学习到的知识点
<div class="member-card"> <!--header外边距体如今外层div上--> <header>{{constellation}}</header> <footer> <div>{{memberGrade}}</div> <div>{{memberName}}</div> </footer> </div>
缘由:
解决方法
<div class="root"> <div class="father"> <div class="child"></div> </div> </div>
let root = document.getElementsByClassName('root')[0]; let father = document.getElementsByClassName('father')[0]; let child = document.getElementsByClassName('child')[0]; root.onclick = function () { console.log("root"); }; father.onclick = function () { console.log("father"); }; child.onclick = function () { console.log("child"); };
点击最内层div时控制台依次显示:child、father、root。按照DOM层次结构像至低向上直到顶端,这就是事件冒泡。
实现弹窗,而后点击空其余任意地方隐藏弹窗
<!--html--> <div class="father"> <div class="child"></div> </div>
/*javascript*/ let father = document.getElementsByClassName('root')[0]; let child = document.getElementsByClassName('child')[0]; father.onclick = function () { console.log("father"); }; child.onclick = function (e) { let ev = e||window.event; ev.stopPropagation(); };
<!--vue--> <div class="father"> <div class="child" @click.stop=""></div> </div>
*模仿网易云音乐播放器页面
地址:https://gitee.com/zhangweiqin...
先了解:rem、em、px
由于rem大小只和根元素字体大小有关因此只要根据设备设置不一样的根元素大小,而后以相同的rem做单位获得的实际大小是不一样的,实现自适应。
document.documentElement.style.fontSize = document.documentElement/375*20 + 'px'; /* 这样 若是在宽度为375(iphone6/7/8)的环境下1rem = 20px. 也能够选择在宽度为360(大部分1080p屏幕)的环境下开发则相应的除以360, 根据设计稿的宽度不一样选择方便计算的方式。 */
App.vue下目前只有主页面以及歌单页面,主界面下两个子路由:个人音乐、发现,两个组件:我的设置页面、播放控制条。
{path: "/", redirect: "/index/myMusic"}, //重定向 {//主界面 path: '/index', name: 'index', component: index, children: [ {//个人音乐 path: '/index/myMusic', name: 'myMusic', component: myMusic }, {//发现 path: '/index/findMusic', name: 'findMusic', component: findMusic } ] }, {//歌单页面 path: '/songList', name: 'songList', component: songList }
路由的使用以及传参:(两种方式)
{ path: 'helloWorld', name: helloWorld, component: ··· } this.$router.push({path: '/helloWorld',query: {msg: 'hello'}}); <router-link :to="{ name: 'helloWorld', query: { msg: 'hello!' }}"></router-link> this.$router.push({ name: 'helloWorld', params: { msg: 'hello'}}); <router-link :to="{ name: 'helloWorld', params: { msg: 'hello' }}"></router-link> console.log(this.$route.query); //{msg:hello},不一样的是query传递参数会被附加到url地址上 console.log(this.$route.params); //{msg:hello}
1. import userSetting from '@/view/modules/userSetting.vue'; 2. const userSetting = resolve => require(['@/view/modules/userSetting.vue'],resolve); //懒加载
异步加载,优势:最大化的实现随用随载,减小首页加载延迟;缺点:可能会形成网页显示过慢且渲染良莠不齐的问题
//单文件组件 components: { userSetting },
父组件->子组件:
<!--发送--> <userSetting :data="'msg from father'"> </userSetting>
//接收 export default { name: "user-setting", props:['data'] }
子组件->父组件:
<!--发送--> <div class="set-item" @click="$emit('msgFromSon','msg from son')"> 高级设置 </div>
<!--接收--> <userSetting v-show="setting" @msgFromSon="recive"> </userSetting>
methods: { recive(msg) { console.log(msg); //msg from son } }
Vue.extend(): 使用基础 Vue 构造器,建立一个“子类”。参数是一个包含组件选项的对象。
let alertOptions = { data:function(){ return { title: title, text: text, } }, methods:{ close() { resolve('ok'); dialogClose(vm); } }, template: '<alert @close="close" :title="this.title" :text="this.text"></alert>', components: {alert} } let creator = Vue.extend(alertOptions)
vm.$mount():手动地挂载一个未挂载的实例。
//挂在到#app下 new creator().$mount('#app') //在文档以外渲染而且随后挂载 vm = new creator().$mount() dialogContainer.appendChild(vm.$el)