根据 Vue文档,它应该在构建生产时删除 HTML 注释。
然而,对我来说,情况并非如此。所有这些<!-- comments -->仍然可以通过生产中的开发工具在 DOM 中可见。有人遇到过吗?
明确设置app.config.compilerOptions.comments = false也没有帮助
我有这个组件 A 和一个公开的方法send
A.vue:
<script setup lang="ts">
function send(data: string) {
console.log(data)
}
defineExpose({ send })
</script>
Run Code Online (Sandbox Code Playgroud)
以及导入该组件的组件B
B.vue
<template>
<ComponentA ref="a" />
</template>
<script setup lang="ts">
import ComponentA from '@/component-a.vue'
const a = ref()
onMounted(() => a.value.send(22)) // should be a type error
</script>
Run Code Online (Sandbox Code Playgroud)
如何键入导入的组件,以便当我通过 refs 调用其方法时,它会检查公开的方法名称和传递参数的类型?
我尝试了谷歌搜索:ComponentPublicInstance<typeof ComponentA>但它似乎没有检查方法。
编辑:
这是 shims-vue.d.ts (由 vue-cli 生成):
declare module '*.vue' {
import type { DefineComponent } from 'vue'
const component: DefineComponent<{}, {}, any>
export default component
}
Run Code Online (Sandbox Code Playgroud)
编辑: …
我有这个代码
.wave {
position: absolute;
height: 90vh;
width: 1920px * 2;
background-image: url(...);
background-size: 1920px 100%;
background-repeat: repeat-x;
animation: wave 3s linear infinite;
@keyframes wave {
0% {
transform: translateX(0);
// left: 0;
}
100% {
transform: translateX(-1920px);
// left: -1920px;
}
}
}
Run Code Online (Sandbox Code Playgroud)
它应该无缝循环,创建连续的波浪运动。不幸的是,在 safari 中,它在每次循环时都会闪烁。我已经尝试了所有的-webkit东西-webkit-backface-visibility: hidden,但没有运气
如果我删除transform: translateX(...)并left设置动画,闪烁就会消失,但transform出于性能原因我想使用
我在这里创建了这个简单的例子
您可以在 safari 中看到每个循环(3 秒)的闪烁。在镀铬下工作得很好
根据文档中的此页面,宏应该是
全局可用,启用反应性变换时无需导入
我已根据此处的文档明确选择了 vue 配置中的反应性转换:
// vue.config.js
config.module.rule('vue')
.use('vue-loader')
.tap((options) => {
return {
...options,
reactivityTransform: true
}
})
Run Code Online (Sandbox Code Playgroud)
但我是从 eslint 得到的'$ref' is not defined。我想我需要在某个地方启用它,以便 eslint 理解它是一个全局宏,但我在文档中找不到任何有关它的信息。
我缺少什么?