Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit bbb98df

Browse files
committed
支持jsx渲染
1 parent b86bae5 commit bbb98df

File tree

2 files changed

+44
-13
lines changed

2 files changed

+44
-13
lines changed

‎build/markdown-loader.js

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -45,10 +45,6 @@ module.exports = function(source) {
4545
// 获取vue组件示例的代码
4646
const nextIndex = tokens[index + 1];
4747
let content = nextIndex.type === "fence" ? nextIndex.content : "";
48-
if (!/^<template>/.test(content)) {
49-
content = `<template><div>${content}</div></template>`;
50-
}
51-
5248
// 将content解析为vue组件基本属性对象;
5349
let { template, script, styles } = parse({
5450
source: content,
@@ -57,10 +53,15 @@ module.exports = function(source) {
5753
});
5854
styleCodeList = styleCodeList.concat(styles);
5955
// 将template的转为render函数
60-
const { code } = compileTemplate({
61-
source: template.content,
62-
compiler: VueTemplateComplier
63-
});
56+
let templateCodeRender = "";
57+
if (template && template.content) {
58+
const { code } = compileTemplate({
59+
source: template.content,
60+
compiler: VueTemplateComplier
61+
});
62+
templateCodeRender = code;
63+
}
64+
6465
// 获取script的代码
6566
script = script ? script.content : "";
6667
if (script) {
@@ -74,12 +75,12 @@ module.exports = function(source) {
7475
const name = `vc-snippent-${componentCodeList.length}`;
7576
// 渲染组件代码添加到数据集合
7677
componentCodeList.push(`"${name}":(function () {
77-
${code}
78+
${templateCodeRender}
7879
${script}
7980
return {
8081
...exportJavaScript,
81-
render,
82-
staticRenderFns
82+
${templateCodeRender ? "render," : ""}
83+
${templateCodeRender ? "staticRenderFns," : ""}
8384
}
8485
})()`);
8586
// 将需要渲染的示例用vc-snippet组件包裹替换插槽显示示例效果

‎src/button/index.md

Lines changed: 32 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,8 +46,38 @@
4646
methods: {
4747
handleButtonClick() {
4848
alert(1);
49-
}
50-
}
49+
},
50+
},
51+
};
52+
</script>
53+
```
54+
55+
:::
56+
57+
## JSX 语法支持
58+
59+
:::snippet 示例代码支持`jsx`渲染。
60+
61+
```html
62+
<script>
63+
export default {
64+
render() {
65+
return (
66+
<div>
67+
<v-button
68+
text="Default"
69+
onClick={() => {
70+
this.handleButtonClick();
71+
}}
72+
></v-button>
73+
</div>
74+
);
75+
},
76+
methods: {
77+
handleButtonClick() {
78+
alert(1);
79+
},
80+
},
5181
};
5282
</script>
5383
```

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /