提交 2e9ef422 编写于 作者: Q qiang

fix: 字节跳动小程序自定义组件支持 v-show 指令

上级 74f861f2
......@@ -72,4 +72,11 @@ describe('mp:compiler-mp-toutiao', () => {
'<view class="{{((\'bg _p\')+\' \'+(classStr1||classStr2))}}">9</view>'
)
})
it('generate v-show directive', () => {
assertCodegen(
'<test v-show="shown">hello world</test>',
'<test bind:-data-custom-hidden="{{!(shown)}}" vue-id="551070e6-1" bind:__l="__l" vue-slots="{{[\'default\']}}">hello world</test>'
)
})
})
......@@ -132,4 +132,11 @@ describe('mp:compiler-mp-weixin', () => {
)
assertCodegen('<test :obj="{x:0}"></test>', '<test vue-id="551070e6-1" obj="{{({x:0})}}" bind:__l="__l"></test>')
})
it('generate v-show directive', () => {
assertCodegen(
'<test v-show="shown">hello world</test>',
'<test data-custom-hidden="{{!(shown)}}" vue-id="551070e6-1" bind:__l="__l" vue-slots="{{[\'default\']}}">hello world</test>'
)
})
})
......@@ -277,10 +277,6 @@ describe('mp:compiler', () => {
'<view v-show="shown">hello world</view>',
'<view hidden="{{!(shown)}}">hello world</view>'
)
assertCodegen(
'<test v-show="shown">hello world</test>',
'<test data-custom-hidden="{{!(shown)}}" vue-id="551070e6-1" bind:__l="__l" vue-slots="{{[\'default\']}}">hello world</test>'
)
})
it('generate DOM props with v-bind directive', () => {
......
......@@ -227,9 +227,17 @@ function traverseDataNode (dataNode, state, node) {
objectExpression.properties.find(valueProperty => {
const isValue = valueProperty.key.name === 'value'
if (isValue) {
let key
// 自定义组件不支持 hidden 属性
const platforms = ['mp-weixin', 'mp-qq']
ret[platforms.includes(state.options.platform.name) && isComponent(node.type) ? ATTE_DATA_CUSTOM_HIDDEN : 'hidden'] = genCode(valueProperty.value, false, true)
const platform = state.options.platform.name
const platforms = ['mp-weixin', 'mp-qq', 'mp-toutiao']
if (isComponent(node.type) && platforms.includes(platform)) {
// 字节跳动小程序自定义属性不会反应在DOM上,只能使用事件格式
key = `${platform === 'mp-toutiao' ? 'bind:-' : ''}${ATTE_DATA_CUSTOM_HIDDEN}`
} else {
key = 'hidden'
}
ret[key] = genCode(valueProperty.value, false, true)
}
return isValue
})
......
......@@ -46,8 +46,9 @@ module.exports = function generateApp (compilation) {
}
// 框架预设样式 用于隐藏自定义组件
const platforms = ['mp-weixin', 'mp-qq']
const presetStyle = platforms.includes(process.env.UNI_PLATFORM) ? '[data-custom-hidden="true"]{display: none !important;}' : ''
// TODO 分平台 import 不同 css
const platforms = ['mp-weixin', 'mp-qq', 'mp-toutiao']
const presetStyle = platforms.includes(process.env.UNI_PLATFORM) ? '[data-custom-hidden="true"],[bind-data-custom-hidden="true"]{display: none !important;}' : ''
if (compilation.assets[`common/main${ext}`]) { // 是否存在 main.css
importMainCss = `@import './common/main${ext}';`
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册