谈一谈组件化
作者:记得要微笑
来源:SegmentFault 思否社区
前言
今天前端生态里面,React、Angular和Vue三分天下。虽然这三个框架的定位各有不同,但是它们有一个核心的共同点,那就是提供了组件化的能力。W3C也有Web Component的相关草案,也是为了提供组件化能力。今天我们就来聊聊组件化是什么,以及它为什么这么重要。
正文
其实组件化思想是一种前端技术非常自然的延伸,如果你使用过HTML,相信你一定有过“我要是能定义一个标签就好了”这样的想法。HTML虽然提供了一百多个标签,但是它们都只能实现一些非常初级的功能。
HTML本身的目标,是标准化的语义,既然是标准化,跟自定义标签名就有一定的冲突。所以从前端最早出现的2005年,到现在2022年,我们一直没有等到自定义标签这个功能,至今仍然是Draft状态。
但是,前端组件化的需求一直都存在,历史长流中工程师们提出过很多组件化的解决方案。
ExtJS
Ext JS是一个流行的JavaScript框架,它为使用跨浏览器功能构建Web应用程序提供了丰富的UI。我们来看看它的组件定义:
MainPanel = function() {
this.preview = new Ext.Panel({
id: "preview",
region: "south"
// ...
});
MainPanel.superclass.constructor.call(this, {
id: "main-tabs",
activeTab: 0,
region: "center"
// ...
});
this.gsm = this.grid.getSelectionModel();
this.gsm.on(
"rowselect", function(sm, index, record) {
// ...
}, this, { buffer: 250 }
);
this.grid.store.on("beforeload", this.preview.clear, this.preview);
this.grid.store.on("load", this.gsm.selectFirstRow, this.gsm);
this.grid.on("rowdbclick", this.openTab, this);
};
Ext.extend(MainPanel, Ext.TabPanel, {
loadFeed: function(feed) {
// ...
},
// ...
movePreview: function(m, pressed) {
// ...
}
});
你可以看到ExtJS将组件设计成一个函数容器,接受组件配置参数options,append到指定DOM上。这是一个完全使用JS来实现组件的体系,它定义了严格的继承关系,以及初始化、渲染、销毁的生命周期,这样的方案很好地支撑了ExtJS的前端架构。
https://www.w3cschool.cn/extjs/extjs_overview.html
HTML Component
搞前端时间比较长的同学都会知道一个东西,那就是HTC(HTML Components),这个东西名字很现在流行的Web Components很像,但却是不同的两个东西,它们的思路有很多相似点,但是前者已是昨日黄花,后者方兴未艾,是什么造成了它们的这种差距呢?
因为主流浏览器里面只有IE支持过HTC,所以很多人潜意识都认为它不标准,但其实它也是有标准文档的,而且到现在还有链接,注意它的时间!
https://www.w3.org/TR/NOTE-HTMLComponents
在MSDN online对HTC的定义仅如下几句:
HTML Components (HTCs) provide a mechanism to implement components in script as Dynamic HTML (DHTML) behaviors. Saved with an .htc extension, an HTC is an HTML file that contains script and a set of HTC-specific elements that define the component.
(HTC是由HTML标记、特殊标记和脚本组成的定义了DHTML特性的组件.)
作为组件,它也有属性、方法、事件,下面简要说明其定义方式:
<PUBLIC:COMPONENT></PUBLIC:COMPONENT>:定义HTC,这个标签是其他定义的父元素。
<PUBLIC:PROPERTY NAME=”pName” GET=”getMethod” PUT=”putMethod” />:定义HTC的属性,里面三个定义分别代表属性名、读取属性、设置属性时HTC所调用的方法。
<PUBLIC:METHOD NAME=”mName” />:定义HTC的方法,NAME定义了方法名。
<PUBLIC:EVENT NAME=”eName” ID=”eId” />:定义了HTC的事件,NAME定义了事件名,ID是个可选属性,在HTC中唯一标识这个事件。
<PUBLID:ATTACH EVENT=”sEvent” ONEVENT=”doEvent” />:定义了浏览器传给HTC事件的相应方法,其中EVENT是浏览器传入的事件,ONEVENT是处理事件的方法。
行为为脚本封装和代码重用提供了一种手段
<HEAD>
<STYLE>
.HILITE
{ color:red;letter-spacing:2; }
</STYLE>
</HEAD>
<BODY>
<UL>
<LI onmouseover="this.className='HILITE'"
onmouseout ="this.className=''">HTML Authoring</LI>
</UL>
</BODY>
// hilite.htc
<HTML xmlns:PUBLIC="urn:HTMLComponent">
// <ATTACH> 元素定义了浏览器传给HTC事件的相应方法,其中EVENT是浏览器传入的事件,ONEVENT是处理事件的方法
<PUBLIC:ATTACH EVENT="onmouseover" ONEVENT="Hilite()" />
<PUBLIC:ATTACH EVENT="onmouseout" ONEVENT="Restore()" />
<SCRIPT LANGUAGE="JScript">
var normalColor;
function Hilite()
{
if (event.srcElement == element)
{
normalColor = style.color;
runtimeStyle.color = "red";
runtimeStyle.cursor = "hand";
}
}
function Restore()
{
if (event.srcElement == element)
{
runtimeStyle.color = normalColor;
runtimeStyle.cursor = "";
}
}
</SCRIPT>
<HEAD>
<STYLE>
LI {behavior:url(hilite.htc)}
</STYLE>
</HEAD>
<BODY>
<UL>
<LI>HTML Authoring</LI>
</UL>
</BODY>
HTC自定义标记
<!—switch.htc定义 -->
<PUBLIC:COMPONENT TAGNAME="Switch">
<!--属性定义-->
<PUBLIC:PROPERTY NAME="turnOnText" PUT="setTurnOnText" VALUE="Turn on" />
<PUBLIC:PROPERTY NAME="turnOffText" PUT="setTurnOffText" VALUE="Turn off" />
<PUBLIC:PROPERTY NAME="status" GET="getStatus" PUT="setStatus" VALUE="on" />
<!--定义事件-->
<PUBLIC:EVENT NAME="onStatusChanged" ID="changedEvent" />
<!--定义方法-->
<PUBLIC:METHOD NAME="reverseStatus" />
<!--关联客户端事件-->
<PUBLIC:ATTACH EVENT="oncontentready" ONEVENT="initialize()"/>
<PUBLIC:ATTACH EVENT="onclick" ONEVENT="expandCollapse()"/>
</PUBLIC:COMPONENT>
<!-- htc脚本 -->
<script language="javascript">
var sTurnOnText; //关闭状态所显示的文本
var sTurnOffText; //开启状态所显示的文本
var sStatus; //开关状态
var innerHTML //使用开关时包含在开关中的HTML
//设置开关关闭状态所显示的文本
function setTurnOnText(value)
{
sTurnOnText = value;
}
//设置开关开启状态所显示的文本
function setTurnOffText(value)
{
sTurnOffText = value;
}
//设置开关状态
function setStatus(value)
{
sStatus = value;
}
//读取开关状态
function getStatus()
{
return sStatus;
}
//反向开关的状态
function reverseStatus()
{
sStatus = (sStatus == "on") ? "off" : "on";
}
//获取htc控制界面html文本
function getTitle()
{
var text = (sStatus == "on") ? sTurnOffText : sTurnOnText;
text = "<div id='innerDiv'>" + text + "</div>";
return text;
}
//htc初始化代码
function initialize()
{
//back up innerHTML
innerHTML = element.innerHTML;
element.innerHTML = (sStatus == "on") ? getTitle() + innerHTML : getTitle();
}
//响应用户鼠标事件的方法
function expandCollapse()
{
reverseStatus();
//触发事件
var oEvent = createEventObject();
changedEvent.fire(oEvent);
var srcElem = element.document.parentWindow.event.srcElement;
if(srcElem.id == "innerDiv")
{
element.innerHTML = (sStatus == "on") ? getTitle() + innerHTML : getTitle();
}
}
</script>
<!--learnhtc.html-->
<html xmlns:frogone><!--定义一个新的命名空间-->
<head>
<!--告诉浏览器命名空间是由哪个HTC实现的-->
<?IMPORT namespace="frogone" implementation="switch.htc">
</head>
<body>
<!--设置开关的各个属性及内部包含的内容-->
<frogone:Switch id="mySwitch"
TurnOffText="off"
TurnOnText="on"
status="off"
onStatusChanged="confirmChange()">
<div id="dBody">文本内容...... </div>
</frogone:Switch>
</body>
<script language="javascript">
//相应开关事件
function confirmChange()
{
if(!confirm("是否改变开关状态?"))
mySwitch.reverseStatus();
}
</script>
</html>
如何定义一个组件
封装:组件屏蔽了内部的细节,组件的使用者可以只关心组件的属性、事件和方法。
解耦:组件本身隔离了变化,组件开发者和业务开发者可以根据组件的约定各自独立开发和测试。
复用:组件将会作为一种复用单元,被用在多处。
抽象:组件通过属性和事件、方法等基础设施,提供了一种描述UI的统一模式,降低了使用者学习的心智成本。
var element = document.createElement('div')
document.getElementById('container').appendChild(element)
function MyComponent(){
this.prop1;
this.method1;
……
}
function MyComponent(){
this.root = document.createElement("div");
this.appendTo = function(node){
node.appendChild(this._root)
}
}
function MyComponent(){
var _root = document.createElement("div");
root.prop1 // = ...
root.method1 = function(){
/*....*/
}
return root;
}
document.getElementById("container").appendChild(new MyComponent());
下面我们根据上面思想来设计一个轮播组件,能够自动播放图片
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<style>
.carousel, .carousel > img {
width: 500px;
height: 300px;
}
.carousel {
display: flex;
overflow: hidden;
}
.carousel > img {
transition: transform ease 0.5s;
}
</style>
</head>
<body>
<script>
let d = [
{
img: "https://static001.geekbang.org/resource/image/bb/21/bb38fb7c1073eaee1755f81131f11d21.jpg",
url: "https://time.geekbang.org",
title: "蓝猫"
},
{
img: "https://static001.geekbang.org/resource/image/1b/21/1b809d9a2bdf3ecc481322d7c9223c21.jpg",
url: "https://time.geekbang.org",
title: "橘猫"
},
{
img: "https://static001.geekbang.org/resource/image/b6/4f/b6d65b2f12646a9fd6b8cb2b020d754f.jpg",
url: "https://time.geekbang.org",
title: "橘猫加白"
},
{
img: "https://static001.geekbang.org/resource/image/73/e4/730ea9c393def7975deceb48b3eb6fe4.jpg",
url: "https://time.geekbang.org",
title: "猫"
}
];
class Carousel {
constructor(data) {
this._root = document.createElement('div');
this._root.classList = ['carousel']
this.children = [];
for (const d of data) {
const img = document.createElement('img');
img.src = d.img;
this._root.appendChild(img);
this.children.push(img);
}
let i = 0;
let current = i
setInterval(() => {
for (const child of this.children) {
child.style.zIndex = '0';
}
// 计算下一张图片的下标
let next = (i + 1) % this.children.length;
const currentElement = this.children[current];
const nextElement = this.children[next];
// 下一张图片的zIndex应该大于当前图片的zIndex
currentElement.style.zIndex = '1';
nextElement.style.zIndex = '2';
// 禁止添加的动画过渡样式
currentElement.style.transition = 'none';
nextElement.style.transition = 'none';
console.log('current', current, next)
// 每次初始化当前图片和下一张图片的位置
currentElement.style.transform = `translate3d(${-100 * current}%, 0 , 0)`;
nextElement.style.transform = `translate3d(${100 - 100 * next}%, 0 , 0)`;
// 浏览器刷新频率是每秒60帧,所以这里需要延迟到浏览器下次重绘更新下一帧动画
setTimeout(() => {
// 启动添加的动画过渡样式
currentElement.style.transition = '';
nextElement.style.transition = '';
// 当前图片退出,下一张图片进来
currentElement.style.transform = `translate3d(${-100 -100 * current}% 0 , 0)`;
nextElement.style.transform = `translate3d(${-100 * next}%, 0 , 0)`;
}, 1000 / 60);
// 或者使用window.requestAnimationFrame,当然这个比较难理解,容易出错,使用setTimeout也是可以的
// window.requestAnimationFrame(() => {
// window.requestAnimationFrame(() => {
// // 启动添加的动画过渡样式
// currentElement.style.transition = '';
// nextElement.style.transition = '';
// // 当前图片退出,下一张图片进来
// currentElement.style.transform = `translate3d(${-100 -100 * current}% 0 , 0)`;
// nextElement.style.transform = `translate3d(${-100 * next}%, 0 , 0)`;
// })
// })
current = next;
i++;
}, 3000);
// 追加
this.appendTo = function(node){
node.appendChild(this._root)
}
}
}
new Carousel(d).appendTo(document.body);
</script>
</body>
</html>
// index.js
const ele = <div id="root" name="container">
<Carousel data={d}></Carousel>
<span>a</span>
<span>b</span>
<span>c</span>
</div>
document.body.appendChild(ele);
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<style>
.carousel, .carousel > img {
width: 500px;
height: 300px;
}
.carousel {
display: flex;
overflow: hidden;
}
.carousel > img {
transition: transform ease 0.5s;
}
</style>
</head>
<body>
<script src="./index.js"></script>
</body>
</html>
// 编译前
const ele = <div id="root" name="container">
<Carousel data={d}></Carousel>
<span>a</span>
<span>b</span>
<span>c</span>
</div>
// 编译后
var ele = React.createElement("div", {id: "root", name: "container"},
React.createElement(Carousel, {data: d}),
React.createElement("span", null, "a"),
React.createElement("span", null, "b"),
React.createElement("span", null, "c")
);
function createElement<P extends {}>(
type: FunctionComponent<P>,
props?: Attributes & P | null,
...children: ReactNode[]): FunctionComponentElement<P>;
function createElement<P extends {}>(
type: ClassType<P, ClassicComponent<P, ComponentState>, ClassicComponentClass<P>>,
props?: ClassAttributes<ClassicComponent<P, ComponentState>> & P | null,
...children: ReactNode[]): CElement<P, ClassicComponent<P, ComponentState>>;
function createElement<P extends {}, T extends Component<P, ComponentState>, C extends ComponentClass<P>>(
type: ClassType<P, T, C>,
props?: ClassAttributes<T> & P | null,
...children: ReactNode[]): CElement<P, T>;
function createElement<P extends {}>(
type: FunctionComponent<P> | ComponentClass<P> | string,
props?: Attributes & P | null,
...children: ReactNode[]): ReactElement<P>;
// index.js
class Carousel {
constructor(data) {
this._root = document.createElement('div');
this._root.classList = ['carousel'];
this.children = [];
}
set data(data) {
this._root.innerHTML = '';
for (const d of data) {
const img = document.createElement('img');
img.src = d.img;
this._root.appendChild(img);
this.children.push(img);
}
let i = 0;
let current = i
setInterval(() => {
for (const child of this.children) {
child.style.zIndex = '0';
}
let next = (i + 1) % this.children.length;
const currentElement = this.children[current];
const nextElement = this.children[next];
currentElement.style.zIndex = '1';
nextElement.style.zIndex = '2';
currentElement.style.transition = 'none';
nextElement.style.transition = 'none';
currentElement.style.transform = `translate3d(${-100 * current}%, 0 , 0)`;
nextElement.style.transform = `translate3d(${100 - 100 * next}%, 0 , 0)`;
setTimeout(() => {
currentElement.style.transition = '';
nextElement.style.transition = '';
currentElement.style.transform = `translate3d(${-100 -100 * current}% 0 , 0)`;
nextElement.style.transform = `translate3d(${-100 * next}%, 0 , 0)`;
}, 1000 / 60);
current = next;
i++;
}, 3000);
}
setAttribute(name, value) {
this[name] = value; // 这里统一attribute和properties,vue使用的是attribute
}
// 追加
appendTo = function(node){
node.appendChild(this._root);
}
}
// index.js
const create = (Class, properity, ...children) => {
let element;
if (typeof Class === 'string') {
// 基本标签直接创建
element = document.createElement(Class);
} else {
// 自定义组件实例化
element = new Class;
}
// 注入到基本标签上的属性直接追加到元素的Attribute属性中,而注入到自定义组件的属性调用组件的setAttribute方法
for (const p in properity) {
element.setAttribute(p, properity[p]);
}
// 处理子节点
for(let child of children) {
if (typeof child === 'string') {
// 如果子节点是字符串,那就创建文本节点
child = document.createTextNode(child);
}
// 如果子节点含有appendTo方法,则是我们自定义的Carousel组件,将子节点追加上当前节点上
if (child.appendTo) {
child.appendTo(element);
} else {
// html标签,也追加到当前节点上
element.appendChild(child);
}
}
return element;
}
// webpack.config.js
const path = require('path')
module.exports = {
entry: "./index.js",
output: {
path: path.resolve(__dirname, 'dist')
},
module: {
rules: [
{
test:/\.js$/,
use:{
loader: "babel-loader",
options: {
presets:["@babel/preset-env"],
plugins: [["@babel/plugin-transform-react-jsx", {pragma: "create"}]]
}
}
}
]
},
mode: "development"
}
/*
* ATTENTION: The "eval" devtool has been used (maybe by default in mode: "development").
* This devtool is neither made for production nor for readable output files.
* It uses "eval()" calls to create a separate source file in the browser devtools.
* If you are trying to read the output file, select a different devtool (https://webpack.js.org/configuration/devtool/)
* or disable the default devtool with "devtool: false".
* If you are looking for production-ready output files, see mode: "production" (https://webpack.js.org/configuration/mode/).
*/
/******/ (() => { // webpackBootstrap
/******/ var __webpack_modules__ = ({
/***/ "./index.js":
/*!******************!*\
!*** ./index.js ***!
\******************/
/***/ (() => {
eval("function _createForOfIteratorHelper(o, allowArrayLike) { var it = typeof Symbol !== \"undefined\" && o[Symbol.iterator] || o[\"@@iterator\"]; if (!it) { if (Array.isArray(o) || (it = _unsupportedIterableToArray(o)) || allowArrayLike && o && typeof o.length === \"number\") { if (it) o = it; var i = 0; var F = function F() {}; return { s: F, n: function n() { if (i >= o.length) return { done: true }; return { done: false, value: o[i++] }; }, e: function e(_e) { throw _e; }, f: F }; } throw new TypeError(\"Invalid attempt to iterate non-iterable instance.\\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.\"); } var normalCompletion = true, didErr = false, err; return { s: function s() { it = it.call(o); }, n: function n() { var step = it.next(); normalCompletion = step.done; return step; }, e: function e(_e2) { didErr = true; err = _e2; }, f: function f() { try { if (!normalCompletion && it[\"return\"] != null) it[\"return\"](); } finally { if (didErr) throw err; } } }; }\n\nfunction _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === \"string\") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === \"Object\" && o.constructor) n = o.constructor.name; if (n === \"Map\" || n === \"Set\") return Array.from(o); if (n === \"Arguments\" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }\n\nfunction _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) { arr2[i] = arr[i]; } return arr2; }\n\nfunction _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError(\"Cannot call a class as a function\"); } }\n\nfunction _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if (\"value\" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } }\n\nfunction _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }\n\nfunction _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }\n\nvar create = function create(Class, properity) {\n var element;\n\n if (typeof Class === 'string') {\n element = document.createElement(Class);\n } else {\n element = new Class();\n }\n\n for (var p in properity) {\n element.setAttribute(p, properity[p]);\n }\n\n for (var _len = arguments.length, children = new Array(_len > 2 ? _len - 2 : 0), _key = 2; _key < _len; _key++) {\n children[_key - 2] = arguments[_key];\n }\n\n for (var _i = 0, _children = children; _i < _children.length; _i++) {\n var child = _children[_i];\n\n if (typeof child === 'string') {\n // 文本节点\n child = document.createTextNode(child);\n }\n\n if (child.appendTo) {\n // Carousel组件\n child.appendTo(element);\n } else {\n // html标签\n element.appendChild(child);\n }\n }\n\n return element;\n};\n\nvar d = [{\n img: \"https://static001.geekbang.org/resource/image/bb/21/bb38fb7c1073eaee1755f81131f11d21.jpg\",\n url: \"https://time.geekbang.org\",\n title: \"蓝猫\"\n}, {\n img: \"https://static001.geekbang.org/resource/image/1b/21/1b809d9a2bdf3ecc481322d7c9223c21.jpg\",\n url: \"https://time.geekbang.org\",\n title: \"橘猫\"\n}, {\n img: \"https://static001.geekbang.org/resource/image/b6/4f/b6d65b2f12646a9fd6b8cb2b020d754f.jpg\",\n url: \"https://time.geekbang.org\",\n title: \"橘猫加白\"\n}, {\n img: \"https://static001.geekbang.org/resource/image/73/e4/730ea9c393def7975deceb48b3eb6fe4.jpg\",\n url: \"https://time.geekbang.org\",\n title: \"猫\"\n}];\n\nvar Carousel = /*#__PURE__*/function () {\n function Carousel(data) {\n _classCallCheck(this, Carousel);\n\n _defineProperty(this, \"appendTo\", function (node) {\n node.appendChild(this._root);\n });\n\n this._root = document.createElement('div');\n this._root.classList = ['carousel'];\n this.children = [];\n }\n\n _createClass(Carousel, [{\n key: \"data\",\n set: function set(data) {\n var _this = this;\n\n this._root.innerHTML = '';\n\n var _iterator = _createForOfIteratorHelper(data),\n _step;\n\n try {\n for (_iterator.s(); !(_step = _iterator.n()).done;) {\n var _d = _step.value;\n var img = document.createElement('img');\n img.src = _d.img;\n\n this._root.appendChild(img);\n\n this.children.push(img);\n }\n } catch (err) {\n _iterator.e(err);\n } finally {\n _iterator.f();\n }\n\n var i = 0;\n var current = i;\n setInterval(function () {\n var _iterator2 = _createForOfIteratorHelper(_this.children),\n _step2;\n\n try {\n for (_iterator2.s(); !(_step2 = _iterator2.n()).done;) {\n var child = _step2.value;\n child.style.zIndex = '0';\n }\n } catch (err) {\n _iterator2.e(err);\n } finally {\n _iterator2.f();\n }\n\n var next = (i + 1) % _this.children.length;\n var currentElement = _this.children[current];\n var nextElement = _this.children[next];\n currentElement.style.zIndex = '1';\n nextElement.style.zIndex = '2';\n currentElement.style.transition = 'none';\n nextElement.style.transition = 'none';\n currentElement.style.transform = \"translate3d(\".concat(-100 * current, \"%, 0 , 0)\");\n nextElement.style.transform = \"translate3d(\".concat(100 - 100 * next, \"%, 0 , 0)\");\n setTimeout(function () {\n currentElement.style.transition = '';\n nextElement.style.transition = '';\n currentElement.style.transform = \"translate3d(\".concat(-100 - 100 * current, \"% 0 , 0)\");\n nextElement.style.transform = \"translate3d(\".concat(-100 * next, \"%, 0 , 0)\");\n }, 1000 / 60);\n current = next;\n i++;\n }, 3000);\n }\n }, {\n key: \"setAttribute\",\n value: function setAttribute(name, value) {\n this[name] = value; // 这里统一attribute和properties,vue使用的是attribute\n } // 追加 \n\n }]);\n\n return Carousel;\n}();\n\nvar ele = create(\"div\", {\n id: \"root\",\n name: \"container\"\n}, create(Carousel, {\n data: d\n}), create(\"span\", null, \"a\"), create(\"span\", null, \"b\"), create(\"span\", null, \"c\"));\ndocument.body.appendChild(ele);\n\n//# sourceURL=webpack://webpack-jsx/./index.js?");
/***/ })
/******/ });
/************************************************************************/
/******/
/******/ // startup
/******/ // Load entry module and return exports
/******/ // This entry module can't be inlined because the eval devtool is used.
/******/ var __webpack_exports__ = {};
/******/ __webpack_modules__["./index.js"]();
/******/
/******/ })()
;