We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
有些东西隔一段时间不用就容易忘记,在此作下记录。
诸如 styleIsolation、virtualHost 等自定义组件配置,声明方式如下:
▼ Composition API
若是 Vue3.3+,可使用 defineOptions()。
<script setup> defineOptions({ options: { virtualHost: false, styleIsolation: 'shared', }, }) // your code... </script>
若是 Vue3.3 以下,需要独立的 <script> 块。
<script>
<script setup> // your code... </script> <script> export default { options: { virtualHost: false, styleIsolation: 'shared', }, } </script>
▼ Options API
<script> export default { options: { virtualHost: false, styleIsolation: 'shared', }, } </script>
主要讨论微信小程序端与 App、H5 等非小程序端的差异。
比如,在父组件查询子组件内的某个元素。
在微信小程序端有两种做法:
uni.createSelectorQuery.in(subComponentInstance).select('.descendant')
uni.createSelectorQuery().select('.ancestor >>> .descendant')
而 App 端,编译后的 HTML 结构跟小程序不一样,小程序带有一个 ShadowRoot 节点隔离,而 App 端不会。因此使用 uni.createSelectorQuery().select('.ancestor .descendant') 直接查询到后代的元素。而且 App 端不支持 >>> 语法,它是小程序特有的。
uni.createSelectorQuery().select('.ancestor .descendant')
在 HTML 中有一种布尔类型的属性。
<!-- attr is true --> <div attr></div> <div attr=""></div> <div attr="false"></div> <div attr="any value"></div> <!-- attr is false --> <div></div>
如果要将某个属性变为 false,只能 removeAttribute('attr')。对于 setAttribute('attr', undefined) 等均是无效的,内部会有 toString() 的处理,因为 HTML 的属性值只能是字符串。data-* 同理。
removeAttribute('attr')
setAttribute('attr', undefined)
data-*
但使用 uniapp 时,不同端表现不一样。
<view data-attr></div>
对于 dataset.attr 微信小程序是布尔值 true,而 App 端则是字符串 '',后者表现是符合 HTML 规范的。猜测是微信小程序内部做了 dataset.attr !== undefined 的处理。如果要用于条件判断,要注意各端值是不一样的。
dataset.attr
true
''
dataset.attr !== undefined
未完待续...
The text was updated successfully, but these errors were encountered:
No branches or pull requests
有些东西隔一段时间不用就容易忘记,在此作下记录。
自定义组件选项配置
诸如 styleIsolation、virtualHost 等自定义组件配置,声明方式如下:
▼ Composition API
若是 Vue3.3+,可使用 defineOptions()。
若是 Vue3.3 以下,需要独立的
<script>
块。▼ Options API
各端差异
后代选择器
比如,在父组件查询子组件内的某个元素。
在微信小程序端有两种做法:
uni.createSelectorQuery.in(subComponentInstance).select('.descendant')
获取元素。uni.createSelectorQuery().select('.ancestor >>> .descendant')
获取其子(子子...)组件内的元素。而 App 端,编译后的 HTML 结构跟小程序不一样,小程序带有一个 ShadowRoot 节点隔离,而 App 端不会。因此使用
uni.createSelectorQuery().select('.ancestor .descendant')
直接查询到后代的元素。而且 App 端不支持 >>> 语法,它是小程序特有的。布尔 dataset
在 HTML 中有一种布尔类型的属性。
如果要将某个属性变为 false,只能
removeAttribute('attr')
。对于setAttribute('attr', undefined)
等均是无效的,内部会有 toString() 的处理,因为 HTML 的属性值只能是字符串。data-*
同理。但使用 uniapp 时,不同端表现不一样。
对于
dataset.attr
微信小程序是布尔值true
,而 App 端则是字符串''
,后者表现是符合 HTML 规范的。猜测是微信小程序内部做了dataset.attr !== undefined
的处理。如果要用于条件判断,要注意各端值是不一样的。未完待续...
The text was updated successfully, but these errors were encountered: