// parent component
export default (){
return (
<div>
<div>1</div>
<ChildComponent />
<div>5</div>
</div>
);
}
// child component
export default (){
return (
<React.Fragment>
<div>2</div>
<div>3</div>
<div>4</div>
</React.Fragment>
);
};
// compiled html tags in browser .
<div>1</div>
<div>2</div>
<div>3</div>
<div>4</div>
<div>5</div>
但是在Vue中,当我做同样的事情时,出现了一些不同之处。
// parent component
<template>
<div>
<div>1</div>
<child-component />
<div>5</div>
</div>
</template>
<script>
import childComponent from 'path/to/childComponent';
export default {
components: { childComponent }
}
</script>
-------------------------------------------------------------
// child component
<template>
<div id='have_to_write_in_vue'>
<div>2</div>
<div>3</div>
<div>4</div>
<div>
</template>
// compiled html tags in browser .
<div>1</div>
<div id='have_to_write_in_vue'>
<div>2</div>
<div>3</div>
<div>4</div>
</div>
<div>5</div>
我问这个问题是因为当出现无用的嵌套时会出现问题。