全局 filter

custom.js

// 2018-11-02 15:12:43  --> 15:12
let subTimeToHour = time => {
    return time.substring(11, 16)
}
export { subTimeToHour }

main.js

import * as customFilters from './filters/custom'
//引入全局filter
Object.keys(customFilters).forEach(key => {
    Vue.filter(key, customFilters[key])
})
  • 需要 webpack 重新编译

引入Swiper

import '../node_modules/swiper/dist/css/swiper.min.css'
import oswiper from '../node_modules/swiper/dist/js/swiper.min.js'
window.Swiper = oswiper

vue在js使用filter

this.$options.filters.[filter名字]

vue 单页应用微信分享在Andriod只有某页设置生效的问题解决

function setWxConfig(rs) {
    setTimeout(() => {
        wx.config({
            debug: false,
            appId: rs.appId, //公众号名称,由商户传入
            timestamp: rs.timestamp, //时间戳,自1970年以来的秒数
            nonceStr: rs.nonceStr, //随机串
            signature: rs.signature, //微信签名方式:
            jsApiList: [
                'openEnterpriseChat',
                'openEnterpriseContact',
                'onMenuShareTimeline',
                'onMenuShareAppMessage',
                'onMenuShareQQ',
                'onMenuShareWeibo',
                'onMenuShareQZone',
                'startRecord',
                'stopRecord',
                'onVoiceRecordEnd',
                'playVoice',
                'pauseVoice',
                'stopVoice',
                'onVoicePlayEnd',
                'uploadVoice',
                'downloadVoice',
                'chooseImage',
                'previewImage',
                'uploadImage',
                'downloadImage',
                'translateVoice',
                'getNetworkType',
                'openLocation',
                'getLocation',
                'hideOptionMenu',
                'showOptionMenu',
                'hideMenuItems',
                'showMenuItems',
                'hideAllNonBaseMenuItem',
                'showAllNonBaseMenuItem',
                'closeWindow',
                'scanQRCode'
            ]
        })
    }, 500)
}

function wxJsConfig(to) {
    let data = {
        url: window.location.href.split('#')[0]
    }

    console.log('WxJsSignature data:', data)
    httpSrv.sendPost(
        null,
        'wx/wx/getWxJsSignature',
        data,
        function(rs) {
            console.log(rs)
            setWxConfig(rs)
        },
        function() {},
        false
    )
}

//vue-router全局守卫
router.afterEach((to, from) => {
    wxJsConfig(to)
    wx.ready(function() {
        wx.hideAllNonBaseMenuItem()
    })
    if (from.meta.keepAlive) {
        from.meta.scroll = $(window).scrollTop()
    }
})