收藏
回答

社区代码块被截掉问题反馈

在社区回复内容时候发送的代码片如果是较长的js或者其他语言,发送出去后查看会被截掉一大部分代码,是回复的代码块,不是提问题的代码块哈,可以复制下方内容回复试试。

export default {
  data() {
    return {
      loading: false
    }
  },


  methods: {
    loginWithWechat() {
      // 这里只适用于 App 端
      // #ifdef APP-PLUS
      this.loading = true


      uni.login({
        provider: 'weixin',
        onlyAuthorize: true,
        success: async (loginRes) => {
          try {
            const code = loginRes.code


            if (!code) {
              throw new Error('微信授权未返回 code')
            }


            const res = await this.requestWechatLogin(code)


            const data = res.data
            if (data.code !== 0) {
              throw new Error(data.message || '登录失败')
            }


            uni.setStorageSync('token', data.data.token)
            uni.setStorageSync('userInfo', data.data.userInfo)


            uni.showToast({
              title: '登录成功',
              icon: 'success'
            })


            uni.reLaunch({
              url: '/pages/index/index'
            })
          } catch (err) {
            uni.showToast({
              title: err.message || '微信登录失败',
              icon: 'none'
            })
          } finally {
            this.loading = false
          }
        },
        fail: (err) => {
          this.loading = false
          uni.showToast({
            title: err.errMsg || '用户取消或授权失败',
            icon: 'none'
          })
        }
      })
      // #endif


      // #ifndef APP-PLUS
      uni.showToast({
        title: '当前示例仅支持 App 端微信登录',
        icon: 'none'
      })
      // #endif
    },


    requestWechatLogin(code) {
      return new Promise((resolve, reject) => {
        uni.request({
          url: 'https://api.example.com/auth/wechat/app-login',
          method: 'POST',
          header: {
            'content-type': 'application/json'
          },
          data: {
            code
          },
          success: resolve,
          fail: reject
        })
      })
    }
  }
}


直接复制粘贴不用代码块时,内容是被转义的,发送出来是正常的。

最后一次编辑于  1天前
回答关注问题邀请回答
收藏

1 个回答

  • 罐梨脆紫柿
    罐梨脆紫柿
    1天前

    测试

    1天前
    有用
    回复 2
    • 罐梨脆紫柿
      罐梨脆紫柿
      1天前
      1天前
      回复
    • 罐梨脆紫柿
      罐梨脆紫柿
      1天前回复罐梨脆紫柿
      <script>
      export default {
        data() {
          return {
            loading: false
          }
        },




        methods: {
          loginWithWechat() {
            // 这里只适用于 App 端
            // #ifdef APP-PLUS
            this.loading = true




            uni.login({
              provider: 'weixin',
              onlyAuthorize: true,
              success: async (loginRes) => {
                try {
                  const code = loginRes.code




                  if (!code) {
                    throw new Error('微信授权未返回 code')
                  }




                  const res = await this.requestWechatLogin(code)




                  const data = res.data
                  if (data.code !== 0) {
                    throw new Error(data.message || '登录失败')
                  }




                  uni.setStorageSync('token', data.data.token)
                  uni.setStorageSync('userInfo', data.data.userInfo)




                  uni.showToast({
                    title: '登录成功',
                    icon: 'success'
                  })




                  uni.reLaunch({
                    url: '/pages/index/index'
                  })
                } catch (err) {
                  uni.showToast({
                    title: err.message || '微信登录失败',
                    icon: 'none'
                  })
                } finally {
                  this.loading = false
                }
              },
              fail: (err) => {
                this.loading = false
                uni.showToast({
                  title: err.errMsg || '用户取消或授权失败',
                  icon: 'none'
                })
              }
            })
            // #endif




            // #ifndef APP-PLUS
            uni.showToast({
              title: '当前示例仅支持 App 端微信登录',
              icon: 'none'
            })
            // #endif
          },




          requestWechatLogin(code) {
            return new Promise((resolve, reject) => {
              uni.request({
                url: 'https://api.example.com/auth/wechat/app-login',
                method: 'POST',
                header: {
                  'content-type': 'application/json'
                },
                data: {
                  code
                },
                success: resolve,
                fail: reject
              })
            })
          }
        }
      }
      </script>
      1天前
      回复
登录 后发表内容