小程序(mpvue框架)的总结

父组件给子组件传参数的时候,最好在组件上加相应判断,不然,传的参数为空。。。

有参(原因,接口初始获取异步,还是内容为空,获取不对,就已经传过去了,所以为undefined)

<comment v-if="article.title" :articleId="articleId" :collect="article.collected"></comment>

无参

<comment  :articleId="articleId" :collect="article.collected"></comment>

不过最好还是用watch来监听他变化

组件内的分享按钮,用的是<button open-type="share" class="icon-share-wxchat"></button>

分享函数要写在父级组件上,很奇怪,而且是在父组件的methods外,竟然不要this.$parent.方法可以直接用(就是不用调用这个方法)神奇

小程序去掉button的边框,用这个button::after{ border: none}

Img mode看情况用。。。

获取某个节点的信息,如坐标,位置,长度,等,用:

wx

.createSelectorQuery()

.select("#节点的id或者.class")

.boundingClientRect(function(rect) {

console.log("节点的上边界坐标" + rect.top);

})

.exec();

}

小程序富文本的rich-txet  里id是无效的;富文本的图片用style="max-width:100%;height:auto"图片自适应

这个不推荐用rich-txet,如果是mpvue框架的,因为mpvue有一个自己的富文本mpvue-wxParse很好用,可以调很多的属性,等等

具体用法参考:http://npm.taobao.org/package/mpvue-wxparse

注意:一些小程序的事件,有bind....什么的,用mpvue就是@...,如bindscrolltoupper就是@scrolltoupper

父组件执行子组件的方法,首先给子组件ref=“x”, this.$refs.x.方法()

子组件执行父组件方法:This.$parent.方法()

微信的上拉,下拉开启

要在main.json里加上"enablePullDownRefresh":true,就可以再methods外写上拉,下拉事件了

// 上拉加载

onReachBottom() {

console.log("上拉");

},

// 下拉刷新

onPullDownRefresh() {

setTimeout(() => {

wx.stopPullDownRefresh();

}, 1500);

}

onUnload(){}//在页面离开的时候执行的函数

onShow(){}//在页面再次加载和首次加载执行的函数

Bindconfirm----@confirm(mpvue)监听手机键盘的输入/完成事件

static目录本来就是用来放静态资源的(要用绝对地址),其他想要压缩的支资源一定要require()或者import引入才可以的,这样webpack才会把文件放到资源图谱里面进行加载

Js字符串取标签及其里面的内容

let getWords= content.match(/<font(([\s\S])*?)<\/font>/g);

Const reg=new RegExp(‘<img’,’gi’);

Result=result.replace(reg,`<img style=”max-width:100%;”`)

Mpvue里获取像小程序的e.detail.value这个

e.mp.detail.value这个才可以,不然会报错

猜你喜欢

转载自www.cnblogs.com/ssszjh/p/10335759.html