一.依旧使用vue2的写法所遇到的问题
1.Property 'codeArr' does not exist on type 'CreateComponentPublicInstance<{}, {}, {}, {}, {}, ComponentOptionsMixin, ComponentOptionsMixin, {}, {}, {}, false, {}, {}, OptionTypesType<{}, {}, {}, {}, {}, {}>, ... 5 more ..., {}>'.

56 |   computed: {
    57 |     isBtnDis() {
  > 58 |       return this.codeArr.length === 6;
       |                   ^^^^^^^
    59 |     }
    60 |   },

解决方法:
所有在computed里面的计算属性的返回值都要注明返回类型
改成:

computed: {
  isBtnDis(): boolean  {
    return this.codeArr.length === 6;                    
  } 
},

2.mapGetters写法错误
解决方法:
改成:

computed: {
    ...mapGetters({ isalive: "alive" })
  },

computed: {
    ...mapGetters("alive")
  },

二.使用vue3的setup写法所遇到的问题
1.调用computed里的值名字后面要加上.value
比如:

setup(){
    const isBtnDis = computed(()=>{
        return return this.codeArr.length === 6;
    })
    console.log(isBtnDis.value)
}

三.vue3与vue2不兼容的地方
1.Vue3的路由重定向的正确写法

{
    path: "/:pathMatch(.*)*",
    redirect: "/home"
}

{
    path: "/:pathMatch(.*)",
    redirect: "/home"
}

{
    path: "/:catchAll(.*)",
    redirect: "/home"
}

2.配置postcss-pxtorem,设计图尺寸是375px,postcss-pxtorem升级之前的写法是rootValue:37.5,但是经过转换后的尺寸却特别的小,页面看起来就像是平板或者pc上的,经过测试发现改成rootValue:16或者viewportWidth: 375会和升级之前的rootValue:37.5几乎没有差别

const { defineConfig } = require("@vue/cli-service");
const autoprefixer = require("autoprefixer");
const pxtorem = require("postcss-pxtorem");

module.exports = defineConfig({
  publicPath: "./",
  outputDir: "dist",
  transpileDependencies: true,
  lintOnSave: false,
  productionSourceMap: false,
  css: {
    loaderOptions: {
      postcss: {
        postcssOptions: {
          plugins: [
            autoprefixer({
              overrideBrowserslist: ["Android >= 4.0", "iOS >= 7"]
            }),
            pxtorem({
              viewportWidth: 375,
              propList: ["*"]
            })
          ]
        }
      }
    }
  }
});

buddha
130 声望2 粉丝

解决移动端技术问题的三大法宝:重启、刷新、换手机