uniapp开发遇到的问题总结

1. input自定义实现v-model时,数据更新后,视图不会更新
/{{subQuestion.score}}
// ...
inputChange (e, questionNum, subQuestion) {
      let subIndex = subQuestion.index
      // hideSubmit定义在data里了
      if (this.hideSubmit) { return false }
      let answer = this.questionData[questionNum].answer || []
      answer.length = this.questionData[questionNum].childrenNum

      let inputValue = e.target.value
      if (inputValue && !this.isValideNumber(inputValue)) {
        Tips.alert('分数不在给定范围内~')
        inputValue = parseInt(inputValue) 
      } else if (inputValue > subQuestion.score) {
        // 提示不能大于总分
        Tips.alert('分数不能大于小题满分')
        inputValue = parseInt(subQuestion.score)
        this.update = false
        this.update = true
      }
      // 先赋值为空
      e.target.value = ''
      answer[subIndex] = answer[subIndex] || ''
      answer[subIndex] = ''
      this.questionData[questionNum]['answer'] = answer
      // update要赋值,以保证不符合输入规则的值正确替换,比如4.6替换成4,大于满分时替换成满分
      this.update = false
      this.update = true
     // 再赋值为处理过的值
      setTimeout(() => {
        e.target.value = inputValue
        answer[subIndex] = inputValue
        this.questionData[questionNum]['answer'] = answer
        this.update = false
        this.update = true
      }, 100)
    }
2. 要拿数据循环的时候,改变其某个属性上的值时,数据改变了,但是视图没有更新

解决方案:
定义一个布尔类型的变量放到页面上去,改变循环的数据的某个属性时,给该变量赋值成false,然后再设置成true

choiceAnswer (questionNum, subIndex, optionName ) {
  // 超过14天后无法修改
  if (this.hideSubmit) { return false }
  let answer = this.questionData[questionNum].answer || []
  answer.length = this.questionData[questionNum].childrenNum
  answer[subIndex] = answer[subIndex] || ''
  if (answer[subIndex].indexOf(optionName)>-1) {
    answer[subIndex] = answer[subIndex].replace(optionName, '')
  } else {
    answer[subIndex] = answer[subIndex].length > 0 ? answer[subIndex].concat(optionName) : optionName
  }
  this.questionData[questionNum]['answer'] = answer
  // 保证页面上用到数据的该属性时页面显示正常
  this.update = false
  this.update = true
}
3. 使用renderjs加载第三方js——实现MathJax公式解析
  

  
  
  
4. 子组件里的生命周期无法触发

只能使用create生命周期去构造了,如果不能满足的话就另想其他办法了

5. input的placeholder样式无法直接覆盖

使用placeholder-class属性设置一个类名,再用该类名写样式去覆盖掉原有的样式

 
6. v-html渲染的图片宽度过大

使用js给img标签添加行内样式以达到目的



...
async onLoad (options) {
      // 获取 equipmentData
      let res = await this.$collectorApi.fetchEquipment(options.id)
      this.equipmentData = res.result
      // 获取 equipmentContentHtml里img标签添加行内样式
      this.equipmentData.equipmentContentHtml= this.equipmentData.equipmentContentHtml
        .replace(/\

7. HbuilderX升级到2.9.0+版本后,旧的代码样式适配出整体被缩小了

经过顽强的询问,搜索,才知道HBuilderX 2.9.0+ 相关更新:调整根字体大小为系统默认大小与微信小程序平台一致,调整后 rem 默认大小不再为 窗口宽度/20,改为了浏览器(webview)默认的字体大小,一般为 16px
这是社区给的解决方案: 更新 HBuilderX 2.9.0+ 后 rpx(upx)、rem 样式变形的处理办法
我做的项目主要是使用 rpx 的部分变形,使用的解决方案为 宽屏适配指南
在里面找到的解决方案如下:
在 pages.json 的 globeStyle 里配置 rpx 的如下参数

"globalStyle": {
  // 省略部分代码...
  "navigationStyle": "custom",
 // rpx 计算特殊处理的值,始终按实际的设备宽度计算,单位 rpx,默认值为 750
  "rpxCalcIncludeWidth": 750 , 
 // rpx 计算所支持的最大设备宽度,单位 px,默认值为 960,我要适配的屏幕宽度为1280,
 // 所以这里的值调整为1280 
  "rpxCalcMaxDeviceWidth": 1280
}

8. Android安全检测报告中检测到WebView File域同源策略绕过漏洞

开发人员无法解决该问题,这是uni-app框架内部要解决的问题,去社区(https://ask.dcloud.net.cn/question/108824)提问也没有人回复
如果一直无法解决该问题APP会被要求下架,如果要用它开发APP,技术选型请慎之又慎

你可能感兴趣的:(uniapp开发遇到的问题总结)