diff --git a/packages/uni-template-compiler/__tests__/compiler-mp-toutiao.spec.js b/packages/uni-template-compiler/__tests__/compiler-mp-toutiao.spec.js index 38b54dfc2a12a5af99e81ace41551c0a574491ba..92a6c8d95f7977250b6d6fc945f7f3d17cef67bb 100644 --- a/packages/uni-template-compiler/__tests__/compiler-mp-toutiao.spec.js +++ b/packages/uni-template-compiler/__tests__/compiler-mp-toutiao.spec.js @@ -1,10 +1,10 @@ const compiler = require('../lib') function assertCodegen (template, templateCode, renderCode = 'with(this){}', options = {}) { - const res = compiler.compile(template, { + const res = compiler.compile(template, { resourcePath: 'test.wxml', mp: Object.assign({ - minified: true, + minified: true, isTest: true, platform: 'mp-toutiao' }, options) @@ -20,13 +20,13 @@ describe('mp:compiler-mp-toutiao', () => { '', '' ) - }) - - it('generate ref', () => { - assertCodegen( - '', - '' - ) + }) + + it('generate ref', () => { + assertCodegen( + '', + '' + ) }) it('generate class binding', () => { @@ -49,10 +49,10 @@ describe('mp:compiler-mp-toutiao', () => { assertCodegen( '

5

', '5' - ) - assertCodegen( - '
6
', - '6' + ) + assertCodegen( + '
6
', + '6' ) // assertCodegen( // `
6
`, @@ -72,4 +72,11 @@ describe('mp:compiler-mp-toutiao', () => { '9' ) }) + + it('generate v-show directive', () => { + assertCodegen( + 'hello world', + 'hello world' + ) + }) }) diff --git a/packages/uni-template-compiler/__tests__/compiler-mp-weixin.spec.js b/packages/uni-template-compiler/__tests__/compiler-mp-weixin.spec.js index 913a31991aa68a94bf3150dd92db9fd38a3d02c5..73ac16d5f2778fa366260b9f8cc76404337f8780 100644 --- a/packages/uni-template-compiler/__tests__/compiler-mp-weixin.spec.js +++ b/packages/uni-template-compiler/__tests__/compiler-mp-weixin.spec.js @@ -132,4 +132,11 @@ describe('mp:compiler-mp-weixin', () => { ) assertCodegen('', '') }) + + it('generate v-show directive', () => { + assertCodegen( + 'hello world', + 'hello world' + ) + }) }) diff --git a/packages/uni-template-compiler/__tests__/compiler.spec.js b/packages/uni-template-compiler/__tests__/compiler.spec.js index 1835c1b98266144b38506106a4032548b95641f4..9b999e9a47b6b5e51a184403931a8e03a137f900 100644 --- a/packages/uni-template-compiler/__tests__/compiler.spec.js +++ b/packages/uni-template-compiler/__tests__/compiler.spec.js @@ -277,10 +277,6 @@ describe('mp:compiler', () => { 'hello world', '' ) - assertCodegen( - 'hello world', - 'hello world' - ) }) it('generate DOM props with v-bind directive', () => { diff --git a/packages/uni-template-compiler/lib/template/traverse.js b/packages/uni-template-compiler/lib/template/traverse.js index 3ffd1bc02fcef01f867d11ffa4cd06a6e8ae3b3f..7c87d3c7778f98d9b3c972bbe0ac6f8166f7a254 100644 --- a/packages/uni-template-compiler/lib/template/traverse.js +++ b/packages/uni-template-compiler/lib/template/traverse.js @@ -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 }) diff --git a/packages/webpack-uni-mp-loader/lib/plugin/generate-app.js b/packages/webpack-uni-mp-loader/lib/plugin/generate-app.js index e108a526aca83b3c96ae53d45395395370fe9ee9..d5a5a0897113ed94c8f3deee4a0e3a7239846325 100644 --- a/packages/webpack-uni-mp-loader/lib/plugin/generate-app.js +++ b/packages/webpack-uni-mp-loader/lib/plugin/generate-app.js @@ -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}';`