饿了么Mint-UI mint-ui.github.io/#!/zh-cncss
main.js 引入html
import MintUI from 'mint-ui'
Vue.use(MintUI);
样式引入 import 'mint-ui/lib/style.css'复制代码
//main.js
import MyUI from './components/common/MyUI';
Vue.component(MyUI.name,MyUI) //组件名称,
组件对象//MyUI.vue
<template>
<ul>
<slot></slot>
</ul>
</template>
<script>
export default {
name: 'my-ul',
}
</script>
//Home.vue 在这个组件引用全局注册的组件
<my-ul></my-ul>复制代码
涉及到 `Moment` `fromNow` `format`vue
命令: npm i moment -S
ios
//main.js
import Moment from 'moment';
Vue.filter('converTime',function(data,formatStr)
{ return Moment(data).format(formatStr)})
//相对时间过滤器
Moment.locale('zh-cn')Vue.filter('relTime',function(time){ //几天前 return Moment(time).fromNow();})
//调用
convertTime('YYYY年MM月DD日')
relTime复制代码
格式转换 <p>发表时间:{{news.add_time | convertTime('YYYY年MM月DD日')}}</p>
几天前使用 {{msg.add_time | relTime}}复制代码
1. 去哪儿
<router-link :to="{name: 'NewsDetail',query: {id: news.id}}" //无需设置路由
<router-link :to="{name: 'NewsDetail',params: {id: news.id}}" //须要设置路由的状态
复制代码
2. 导航
{name: 'NewsDetail',path: '/news/detail/:id',component: Xxx}复制代码
3. 详情页接收
created 获取路由参数,发请求获取详情数据 this.$route.params.id复制代码
//列表
route:{name:'PhotoList',query:{categoryId:0}
//详情
let { categoryId } = this.$route.query;this.$axios.get('getimages/' + categoryId)复制代码
this.categories.unshift({id: 0 ,title: '所有'})复制代码
编程式路由传值更改连接的id
@click="navigateToCateById(category.id)"
methods:{navigateToCateById(id) {
this.$router.push({
name:'PhotoList', //文件名
query:{ categoryId:id }
});},}复制代码
beforeRouteUpdate (to, from, next) { //路由更新
// console.log(to);
// console.log(from);
let { categoryId } = to.query;
// 发请求更改页面数据
this.loadImgsById(categoryId);
next();
// 在当前路由改变,可是该组件被复用时调用
// 举例来讲,对于一个带有动态参数的路径 /foo/:id,在 /foo/1 和 /foo/2 之间跳转的时候,
// 因为会渲染一样的 Foo 组件,所以组件实例会被复用。而这个钩子就会在这个状况下被调用。
// 能够访问组件实例 `this`
},复制代码
来自组件的懒加载 <img v-lazy="item">
image[lazy=loading] {
width: 40px;
height: 300px;
margin: auto;
}
//不是来自第三方的懒加载
install vue-lazyload --save-dev ' import VueLazyload from 'vue-lazyload' Vue.use(VueLazyload) <img v-lazy="emptyGif"> 复制代码
//main.js
给vue的原型挂载$axios属性
Vue.prototype.$axios = Axios;
Axios.defaults.baseURL = 'https://www.sinya.online/api/'
//全局接口请求
拦截器
//须要加载中的过渡之类,开始定义拦截器(拿请求体,请求头)//请求发起前
Axios.interceptors.request.use(function(config) {
MintUI.Indicator.open({
text: '加载中...',
spinnerType: 'fading-circle'
});
return config;
})//响应回来后
Axios.interceptors.response.use(function(response) {
//reponse: { config: {},data:{},headers}
//接收响应头或者响应体中的数据,保存起来,供请求的拦截器使用头信息操做
MintUI.Indicator.close(); return response; })
复制代码
页面请求数据的写法 this.$axios.get('getnewslist').then(res => {}).catch(err => {})复制代码
在接收这个DOM的组件中,能给solt之后的元素设置样式,而没有能给slot设置样式git
<solt name="icon"></solt>
<img slot="icon" src="../img/jj.png">复制代码
1. /xxx?id = 1 配置路由规则 path: 'xxx' 组件接收 this.$route.query.id 传递 to:{query:{id:1}}
1. /xxx/1 配置路由规则 path: 'xxx/:id' 组件接收 this.$route.params.id {params:{id:1}}复制代码
https://www.npmjs.com/package/vue-preview
安装 npm i vue-preview -S
使用的时候须要传入w,h,msrc复制代码
考虑和注意的问题github
输入框 须要绑定声明 v-model="content"
发送数据
this.$axios.post(`postcomment/${this.cid}`,`content = ${this.content}`).then(res => {
this.init();//页码初始化
this.loadMsgByPage() //请求数据接口再渲染次数据
}对加载更多进行追加
if (this.page ===1) {
this.msgs = res.data.message //赋值
} else {
this.msgs = this.msgs.concat(res.data.message) //追加
}页数递增 `this.page ++;`数据少于十条
if( res.data.message.length <10 && this.page !=1) {
this.$toast({
message: '没有数据', iconClass: 'icon icon-success'
})
// 禁止点击
this.disabled = true; return ;}复制代码
//控制字数显示过滤器Vue.filter('controllShow',function(str,num){
// 若是当前字符串小于num,返回原来值 if(str.length < num){ return str; }
//若是当前的字符串大于num,截取0-num-1位
if(str.length > num) { return str.substr(0,num-1) + '...'; }})
调用
<div class="title">{{goods.title | controllShow(23)}}</div>
复制代码
相关连接: www.cnblogs.com/zhouyangla/…
npm
let imgReq = this.$axios.get(`getthumimages/${this.goodsId}`);
let infoReq = this.$axios.get(`goods/getinfo/${this.goodsId}`);
// 合并请求 $axios.all([]).then(传播响应).catch()
this.$axios.all([imgReq,infoReq])
.then( this.$axios.spread( (imgRes,infoRes)=>{ this.imgs = imgRes.data.message; this.info = infoRes.data.message[0]; }) )复制代码
服务端和客户端读取数据的区别,单页面应用和多页面加载出现的区别,先后端分离真正的缘由,此处在第四季vue的第四天商品列表、购物车-02编程