账号密码登录
微信安全登录
微信扫描二维码登录

登录后绑定QQ、微信即可实现信息互通

手机验证码登录
找回密码返回
邮箱找回 手机找回
注册账号返回
其他登录方式
分享
  • 收藏
    X
    在vue methods中定义了一个方法, 提示错误Symbol is not a constructor应该怎么修改?
    32
    0

    在vue methods中定义了一个方法,其中这句 this.annotationsPoint = new Symbol(rect)
    提示错误Symbol is not a constructor应该怎么修改?

        drawAnnotationPoint(centerPoint) {
            if (!this.annotationsPoint) {
              const topLeft = new Point(centerPoint.x - this.getRealDistance(this.pointSize / 2), centerPoint.y - this.getRealDistance(this.pointSize / 2))
              const rectSize = new Size(this.getRealDistance(this.pointSize), this.getRealDistance(this.pointSize))
              const rect = new Path.Rectangle(topLeft, rectSize)
              rect.fillColor = '#5446ff'
              this.annotationsPoint = new Symbol(rect)
            }
    
            return this.annotationsPoint.place(centerPoint)
          },

    直接把 new关键字去掉下行会提示this.annotationsPoint.place is not a function

    1
    打赏
    收藏
    点击回答
    您的回答被采纳后将获得:提问者悬赏的 10 元积分
        全部回答
    • 0
    • 在 Vue 中,Symbol 是一种特殊的类型,用于标识和区分不同的对象或值。但是,你已经明确指出错误在于使用了 Symbol 作为构造函数的参数。这是因为 Vue 中的构造函数参数是不允许使用 Symbol 的,因为这可能会导致代码的不可预测性。

      要修复这个问题,你需要将 Symbol 替换为一个普通的变量,例如:

      ```javascript let symbol = Symbol();

      methods: { ...superMethods, // 指示你仍在调用 superMethods myMethod() { console.log(symbol); // 输出 'symbol' } } ```

      这样,你就可以使用 symbol 作为构造函数参数,而不用担心它的安全性问题了。

    更多回答
    扫一扫访问手机版
    • 回到顶部
    • 回到顶部