美文网首页
uni迁移到Taro

uni迁移到Taro

作者: NanaCti | 来源:发表于2023-12-14 10:39 被阅读0次
  • node版本切到14

  • 全局安装taro-cli, 参考taro快速开始

  • 创建项目时候选择webpack4

  • uni.api 修改为Taro.api

注意uni的api使用时不需要引入uni, Taro需要导入import Taro from '@tarojs/taro'

uni.getStorage()
// =>
import Taro from '@tarojs/taro'
Taro.getStorage()
  • Taro 不支持style标签的scoped, 改成CSS Modules
  1. 在配置中开启CSS Modules, 参考taro
<style lang="scss" scoped>
// => 
<style lang="scss" module>


class="main"
// => 
:class="$style['main']"

// 搜索框快速替换正则
class="([^"]+)"
:class="$style['$1']"

// 多类名或者原本有:class属性的需要再修改
:class="{
    [$style['class1']]: true,
    [$style['class2']]: true
  }"

image.png
  • taro不支持部分html标签, 需要转成v-html写法, 通过addEventListener添加事件

相关文章

网友评论

      本文标题:uni迁移到Taro

      本文链接:https://www.haomeiwen.com/subject/vltpgdtx.html