问题描述:
在尝试在uniapp中使用vue3时点击事件报错. H5正常, 但在app中报错.
报错如下:
Uncaught TypeError: Cannot assign to read only property 'type' of object '#<MouseEvent>' at uni-app-view.umd.js:3
代码:
<!-- index.vue -->
<template>
<view class="content">
<div class="cid-box">
<div class="cid">cid is: {{cid}}</div>
<div class="copy-cid" @click="copyCid">copy cid</div>
</div>
<div class="push-box">
<div class="type">push type is: {{type}}</div>
<div class="msg">push message is: {{msg}}</div>
</div>
</view>
</template>
<script >
import vm from "./index.js";
export default vm;
</script>
<style src="./index.scss" lang="scss"></style>
// index.js
import { initCid, initPush } from "./lib";
export default {
setup() {
const { cid, copyCid } = initCid();
const { type, msg } = initPush();
return { cid, type, msg, copyCid };
},
};
// lib.js
import { ref } from "vue";
export function initCid() {
const cid = ref("");
function getCid() {
// #ifdef APP-PLUS
const pinf = plus.push.getClientInfo();
cid.value = pinf.clientid;
// #endif
}
function copyCid() {
// #ifdef APP-PLUS
if (cid.value) {
uni.setClipboardData({
data: cid.value,
});
} else {
getCid();
}
// #endif
}
getCid();
return { cid, copyCid };
}
export function initPush() {
const type = ref("");
const msg = ref("");
// #ifdef APP-PLUS
console.log("initPush");
plus.push.addEventListener(
"click",
(msg) => {
type.value = "click";
msg.value = msg;
},
false
);
plus.push.addEventListener(
"receive",
(msg) => {
type.value = "receive";
msg.value = msg;
},
false
);
// #endif
return { type, msg };
}
r***@qq.com (作者)
没有解决, 暂时还是用vue2了
2022-02-14 16:22