Skip to content

Uncaught TypeError: Cannot read properties of undefined (reading 'prototype')

2023-05-19-14-49-43

js
// uno.config.ts
shortcuts: [['f-s-c', 'flex justify-start items-center']]
  1. 写在类名上不生效
html
<!--f-s-c 直接写在类名上不生效-->
<div class="hidden lg:f-c-c">Test</div>
  1. 写在 CSS 上报错
html
<div class="nav">Test</div>
css
// f-s-c 报错;The `xl:f-c-c` class does not exist. If `xl:f-c-c` is a custom class, make sure it is defined within a `@layer` directive.

.nav {
  @apply hidden lg:f-c-c;
}

解决方法:断点后不写自定义的

html
<div class="hidden lg:flex justify-center items-center">Test</div>

总结:自定义的类名快捷键不能写在变体后面

hidden 与自定义变体不能一起用

ts
// uno.config.ts
shortcuts: [
  ['f-s-c', 'flex justify-start items-center'],
  ['f-c-c', 'flex justify-center items-center'],
]
html
<div class="hidden xl:f-c-c">TEST</div>

可以这样用

html
<div class="f-s-c xl:f-c-c">TEST</div>

项目一直报 Element 相关错误

element-ui.js:1 Uncaught TypeError: Cannot read properties of undefined (reading 'prototype')2023-05-21-20-26-38 换浏览器后没报错,定位到可能是浏览器插件的原因,果然排除法找到是:YouTube 视频摘要 ChatGPT 生成-快速笔记 (中文版) 的问题!

跨域问题

js
export default defineNuxtConfig({
  /* ... */
  nitro: {
    devProxy: {
      '/account/api': {
        target: 'http://192.168.211.63/account/api',
        // target: 'http://192.168.211.63', 【不生效】 不同于 vite,这样配置到达 nginx 是 '/'
        ws: false,
        changeOrigin: true,
      },
    },
  }
})
js
// 业务请求
async function getImgCode() {
  const { data, pending, error, refresh, clear } = await useFetch('/account/api/getImageCode', {
    method: 'POST',
    body: {},
  })
  return data.value
}

nuxt-simple-sitemap插件使用问题

打包时报错:解析到错误 URL

js
export default defineNuxtConfig({
  nitro: {
    prerender: {
      crawlLinks: true,
      routes: ['/'], // 去掉: ,'sitemap.xml'
    },
  }
})

测试环境能访问sitemap.xml 页面 但是线上环境访问不到,报相关错误:/__sitemap__/routes.json ,需要在 nginx 配置 IP 和主机名的传送。

zsh
  # nginx.conf
   proxy_set_header X-Real-IP $remote_addr;
   proxy_set_header Host $host;