<audio src="课堂示例/梦然-少年.mp3" controls autoplay loop muted>audio> 内联
<audio controls>
<source src="课堂示例/梦然-少年.ogg" type="audio/ogg">source>
<source src="课堂示例/梦然-少年.mp3" type="audio/mpeg">source>
你的浏览器不支持此文件,换个电脑吧
audio>
<video src="课堂示例/qr.ogg" controls height="300" autoplay loop muted>
video>
<video controls>
<source src="课堂示例/wje.mp4" type="video/mp4">source>
<source src="课堂示例/wje.ogg" type="video/ogg">source>
<source src="课堂示例/wje.webm" type="video/webm">source>
video>
<input type="text" required autofocus>
<input type="text" name="test" autocomplete="on" >
<input type="file" multiple>
<input type="text" pattern="[0-9]"> 限制输入0-9之间的数
使用:animation: 动画名 动画持续时间 延迟时间 动画效果 执行次数
定义动画
@keyframes 动画名{
from{
} ==>0%
to{
}==>100%
}
关键帧分的是时间
@keyframes 动画名{
0%{
css属性:css属性值
}
10%{
} 0.5s
20%{
} 1s
30%{
}
100%{
}
}
/* 0%-40% 是红色的纯色 40%-60% 红色到蓝色渐变 60%-100% ;蓝色的纯色*/
background: linear-gradient(red 40%, blue 60%);
background: radial-gradient(left, red, blue);
background: -webkit-radial-gradient(left, red, blue);
background: -ms-radial-gradient(left, red, blue);
.clear:after{
content:"";
display:block;
clear:both;
height:0;
overflow:hidden;
visibility:hidden
}
父元素:before{
content:"";
display:inline-block;
vertical-align:middle;
height:100%;
}
div {
height: 0;
border-top: 20px solid pink;
border-right: 20px solid transparent;
border-bottom: 20px solid transparent;
border-left: 20px solid transparent; /*透明*/
width: 0;
}
btn.onclick = function(){
// 1. 实例化一个XMLHttpRequest对象
let http = new XMLHttpRequest();
// 2. 规划一个请求(三要素)
// 2.1 请求方式 GET || POST
// 2.2 请求地址
// 2.3 同步还是异步 可选的参数,如果省略就是异步的请求
//http.open("GET","http://10.35.170.103/data.php");
//带有一个请求参数的请求
http.open("GET",`http://10.35.170.103/data.php?age=${
age.value}&sex=${
sex.value}`);
// 3. 真实的发送请求
http.send();
// 4. 接收来自服务器端的响应
http.onreadystatechange = function(){
//服务器端已将返回的内容交付给客户端手里了
if(http.readyState === 4){
console.log(http.responseText);
}
}
}
var xml;
if (window.XMLHttpRequest) {
xml=new XMLHttpRequest();
}else{
xml=new ActiveXObject("Microsoft.XMLHTTP");
}
xml.open("get","index.json",true);
xmlH.send();// get请求send保持为空
xml.open("post","index.json",true);
//如果想要使用post提交数据,必须添加此行
xhr.setRequestHeader("Content-type", "application/x-www-form-urlencoded"); //将数据通过send方法传递
xhr.send('name=fox&age=18');
xml.onreadystatechange(function(){
if(xmlHttp.readyState==4&&xmlHttp.status==200){
console.log(xhr.responseText);
}
}
function isNaN(n) {
if (n !== n) {
return true;
} else {
return false;
}
}
var a=NaN;
a==a; //false
console.log(Object.is("a", NaN));
console.log(Object.is(1, NaN));
console.log(Object.is(NaN, NaN));
let fn = (function(){
//局部变量
var count = 0;
return function(){
return ++count;
}
})()
特性 | Cookie | localStorage | sessionStorage |
---|---|---|---|
数据的生命期 | 一般由服务器生成,可设置失效时间。如果在浏览器端生成Cookie,默认是关闭浏览器后失效 | 除非被清除,否则永久保存 | 仅在当前会话下有效,关闭页面或浏览器后被清除 |
存放数据大小 | 4K左右 | 一般为5MB | 同左 |
与服务器端通信 | 每次都会携带在HTTP头中,如果使用cookie保存过多数据会带来性能问题 | 仅在客户端(即浏览器)中保存,不参与和服务器的通信 | 同左 |
易用性 | 需要程序员自己封装,源生的Cookie接口不友好 | 源生接口可以接受,亦可再次封装来对Object和Array有更好的支持 | 同左 |
var arr = [1, 5, 6, 1, 3, 4, 11, 2, 5]
//排序 固定写法 升序
arr.sort(function(num1, num2) {
return num1 - num2;
})
console.log(arr);
//排序 固定写法 降序
arr.sort(function(num1, num2) {
return num2 - num1;
})
console.log(arr);
export default new Vuex.Store({
state: {
},//存放数据
mutations: {
},//修改数据的值
actions: {
},//执行异步操作请求数据
modules: {
},//让每一个模块拥有自己的state、mutation、action、getters,使得结构非常清晰,方便管理。
getters:{
}//计算属性
})
app.use("/", (req, res, next) => {
res.header('Access-Control-Allow-Origin', '*');
res.header('Access-Control-Allow-Headers', 'Content-Type,Content-Length, Authorization, Accept, X-Requested-With , yourHeaderFeild');
res.header('Access-Control-Allow-Methods', 'PUT, POST, GET, DELETE,OPTIONS');
next()
})
methods: {
getData () {
var self = this
$.ajax({
url: 'http://f.apiplus.cn/bj11x5.json',
type: 'GET',
dataType: 'JSONP',
success: function (res) {
self.data = res.data.slice(0, 3)
self.opencode = res.data[0].opencode.split(',')
}
})
}
}
proxy: {
'/api': {
target: 'http://localhost:3000/', //对应自己的接口
changeOrigin: true,
ws: true,
pathRewrite: {
'^/api': ''
}
}
}
{
path: '/info:aa',name: 'Info',component: Info} //在router下的index.js中,aa表示随意绑定的参数
<router-link :to="{name:'tema',params:{id:'参数1',name:'参数2'}}">index</router-link>
this.$router.push({
name:'tema',params:{
id:'参数1',name:'参数2'}})
{
{
this.$route.params.id}} //在接收页面添加,id指的是在路由规则里绑定的参数
<router-link :to="/home?id=参数1&name=参数2">index</router-link>
//通过name引用路由
<router-link :to="{name:'tema',query:{id:'参数1',name:'参数2'}}">index</router-link>(推荐)
//通过path引用路由
<router-link :to="{path:'/home',query:{id:'参数1',name:'参数2'}}">index</router-link>
this.$router.push("/home?id=参数1&name=参数2");
//通过name引用路由
this.$router.push({
name:'tema',query:{
id:'参数1',name:'参数2'}});
//通过path引用路由
this.$router.push({
path:'/home',query:{
id:'参数1',name:'参数2'}});
{
{
this.$route.query.id}} //在接收页面添加,id指的是在路由规则里绑定的参数
Vue.component('name',{
template:''
})
data:function(){
return {
a:1,b:2}
}
methods:{
函数名:function(){
}
}
router.beforeEach((to,from,next)=>{
//根据用户的登录状态限制用户是否能跳转到首页面
if(to.path=="/login"||to.path=="/register"){
next()
} else {
alert("当前为付费页面 请登录后访问!")
next("/login")
}
})
router.afterEach((to,from)=>{
console.log("我是全局后置钩子");
})
{
path:'/shop',
name:'Shop',
component:Shop,
beforeEnter:(to,from,next)=>{
//判断是否登录过
alert("当前页面是vip页面!请登录")
next("/login")
}
}
beforeRouteLeave(to,from,next){
if(confirm("你确定要离开吗")){
next()
}else{
//不进行下一步(也就是不从当前路由离开)
next(false)
}
}
{
path: '/info:aa',name: 'Info',component: Info} //在router下的index.js中,aa表示随意绑定的参数
<router-link :to="{name:'tema',params:{id:'参数1',name:'参数2'}}">index</router-link>
this.$router.push({
name:'tema',params:{
id:'参数1',name:'参数2'}})
{
{
this.$route.params.id}} //在接收页面添加,id指的是在路由规则里绑定的参数
<router-link :to="/home?id=参数1&name=参数2">index</router-link>
//通过name引用路由
<router-link :to="{name:'tema',query:{id:'参数1',name:'参数2'}}">index</router-link>(推荐)
//通过path引用路由
<router-link :to="{path:'/home',query:{id:'参数1',name:'参数2'}}">index</router-link>
this.$router.push("/home?id=参数1&name=参数2");
//通过name引用路由
this.$router.push({
name:'tema',query:{
id:'参数1',name:'参数2'}});
//通过path引用路由
this.$router.push({
path:'/home',query:{
id:'参数1',name:'参数2'}});
{
{
this.$route.query.id}} //在接收页面添加,id指的是在路由规则里绑定的参数
图标导航二
导航标题 //directives:{
//自定义指令的名字:{
//自定义指令钩子函数(el){
//操作逻辑
//}
//}
//}
<template>
<div class="about">
<h1 v-aa>自定义指令</h1>
</div>
</template>
<script>
export default {
directives:{
"aa":{
// el指向当前绑定的那个元素
inserted(el){
el.style.color="pink"
}
}
}
}
</script>
```
Vue.filter('过滤器名称',function(val){
//val表示需要处理的值
return val + 4; //返回处理后的数据
})
filters:{
"过滤器名字":function(val){
return输出内容
}
}
<keep-alive include="Democ">
<component :is="com"></component>
</keep-alive>
export default {
data(){
return{
text:"demoa"
}
},
activated() {
console.log("进入到被keepalive管理的组件");
},
deactivated() {
console.log("离开了被keepalive管理的组件");
}
}
{
path: '/',
name: 'Home',
//路由懒加载
component: () => import ('../views/Home.vue')
}
<button @click="fun()">点我发送请求</button>
export default {
methods: {
fun(){
this.$store.dispatch("ajaxdemo")
}
},
}
mutations: {
uparr(state, payload) {
state.arr = payload
}
},
actions: {
ajaxdemo(store) {
axios({
url: "http://api.artgoer.cn:8084/artgoer/api/v1/user/324380/v3/topic/topicHomeByLabel?pageIndex=1&token=b544cd63-6d42-46fe-a96c-3cf96bae3113&topicId=62187",
method: "get"
}).then((ok) => {
console.log(ok);
store.commit("uparr", ok.data.data.commentList)
})
}
}
actions: {
axioslink(store) {
demoapi.demo().then((ok) => {
console.log(ok.data.data.commentList);
// 把请求来的数据给mutations进行state的修改
store.commit("uparr", ok.data.data.commentList)
})
}
}
{
{
this.$store.state.name}}
computed:{
obj(){
return this.$store.state.obj
}
}
getters: {
nameone(state) {
return state.name.toUpperCase()
},
nametwo(state) {
return state.name.substr(0, 2)
}
}
<p>{
{
this.$store.getters.nameone}}</p>
<p>{
{
this.$store.getters.nametwo}}</p>
mutations: {
upone(state) {
//创建一个方法,且必须有一个形参,对应要修改的那个数据state
state.name = "haha"
}
}
methods:{
fun(){
//调用mutations的commit()函数
this.$store.commit("upone")
}
}
mutations: {
uptwo(state, payload) {
state.name = payload
}
}
methods:{
funb(){
// this.$store.commit("uptwo",把要传递给mutations的数据放到这里)
this.$store.commit("uptwo",this.inputval)
}
}
this.$store.commit('add',{'name':'lxg','num':20...})
actions: {
axioslink(store) {
demoapi.demo().then((ok) => {
console.log(ok.data.data.commentList);
// 把请求来的数据给mutations进行state的修改
store.commit("uparr", ok.data.data.commentList)
})
}
},
methods:{
func(){
//调用actions来进行异步请求
this.$store.dispatch("axioslink")
}
}
mutations: {
uparr(state, payload) {
state.arr = payload
}
}
export default new Vuex.Store({
state: {
},
mutations: {
},
actions: {
},
modules: {
}
})
component:resolve=>(require(["引用的组件路径"],resolve))
const HelloWorld = ()=>import('需要加载的模块地址')
<img v-lazy="1.jpg">
<script type="text/babel">
// 函数名使用大驼峰命名规范
function MyCom(){
return (
<div>
<h1>我是一个react无状态组件</h1>
</div>
)
}
ReactDOM.render(<MyCom/>,document.getElementById("demodiv"))
</script>
<script type="text/babel">
class MyCom extends React.Component{
render(){
return (
<div>
<h1>我是一个react类组件</h1>
</div>
)
}
}
class Fu extends React.Component{
render(){
return (
<div>
<MyCom/>
<MyCom/>
<MyCom/>
</div>
)
}
}
ReactDOM.render(<Fu/>,document.getElementById("demodiv"))
</script>
funa(){
this.setState({
text:"我变了1"
})
}
<button onClick={
this.funa.bind(this)}>方式1:通过bind方法进行原地绑定,从而改变this指向</button>
funb=()=>{
this.setState({
text:"我变了2"
})
}
<button onClick={
this.funb}>方式2:通过创建箭头函数</button>
func(){
this.setState({
text:"我变了3"
})
}
<button onClick={
this.func}>方式3:在constructor中提前对事件进行绑定</button>
fund(){
this.setState({
text:"我变了4"
})
}
<button onClick={
(e)=>{
this.funb("参数1","参数2",e)}}>通过箭头函数传递</button>