App.vue onLaunch 中添加以下代码
const _self = this;
const _handlePush = function(message) {
_self.updatePushMessage(message);
uni.navigateTo({
})
};
var platform = uni.getSystemInfoSync().platform;
plus.push.addEventListener("click", function(msgc) {
if (platform == 'ios') {
if (typeof msgc.payload == 'string' && msgc.payload.indexOf('{') > -1) {
var paymsg = JSON.parse(msgc.payload);
} else {
console.log('obj')
var paymsg = msgc.payload;
}
console.log(paymsg)
}
_handlePush(msgc)
}, false);
plus.push.addEventListener("receive", function(msg) {
if (msg.type == "receive")
{
if (platform == 'ios') {
console.log(msg.payload)
plus.push.createMessage(
msg.payload,
JSON.stringify(msg.payload), {
cover: false,
title: msg.title,
});
}
}
if (platform == 'android') {
}
}, false);
store 设置
import Vue from 'vue'
import Vuex from 'vuex'
Vue.use(Vuex)
const store = new Vuex.Store({
import {
createStore
} from 'vuex'
const store = createStore({
state: {
pushMessage: {}
},
getters: {
pushMessage: state => state.pushMessage,
},
mutations: {
updatePushMessage(state, message) {
let payload = message.payload;
if (typeof payload !== 'string') {
message.payload = JSON.stringify(payload);
}
state.pushMessage = message || {};
}
}
})
export default store
|