r***@qq.com
r***@qq.com
  • 发布:2022-01-06 16:03
  • 更新:2022-02-11 19:44
  • 阅读:593

vue3 click事件报错

分类:uni-app

问题描述:
在尝试在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 };  
}
2022-01-06 16:03 负责人:无 分享
已邀请:
1***@163.com

1***@163.com

兄弟,这个问题解决了吗?

  • r***@qq.com (作者)

    没有解决, 暂时还是用vue2了

    2022-02-14 16:22

2***@qq.com

2***@qq.com

vue3太多不稳定因素了
之前碰到过这个问题 换了个版本后解决了
现在又更新了个新版本 又出这个错误了

该问题目前已经被锁定, 无法添加新回复