打字机输出效果,且滚动到底部效果

    // 打印文本   可根据参数区分

typeText(type, text, cb) {

      let index = 0;

      this.typeTextTimer = raf.setInterval(() => {

        if (index < text.length) {

          if (type === "welcome") {

            this.welcomeMsg += text.charAt(index);

          } else if (type === "wakeup") {

            this.wakeupTips += text.charAt(index);

          }

          index++;

          this.scroll2bottom(true);

        } else {

          this.scroll2bottom(true);

          if (type === "welcome") {

            this.showWelcomeMsg = false;

          }

          raf.clearInterval(this.typeTextTimer);

          cb && cb();

        }

      }, 150);

    },

    // 滚动到容器底部

    scroll2bottom(isWelcomeMsg = false) {

      this.$nextTick(() => {

        const askTextDom = isWelcomeMsg

          ? this.$refs.welcomeMsgDom

          : this.$refs.askTextDom;

        askTextDom &&

          askTextDom.scrollTo({

            top: askTextDom.scrollHeight,

            behavior: "smooth",

          });

      });

    },

     // 方法调用


        this.typeText("welcome", this.tempWelcomeMsg, () => {

                if (process.env.VUE_APP_SHOW_TIPS === "true") {

                  this.$message.error(

                    "无唤醒词,设置 asr 类型为 0(语音识别)"

                  );

                }

                this.setAsrType(0);

                this.initRecorder();

                this.setRecordingBtnVisible(true);

        });

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值