File tree Expand file tree Collapse file tree 2 files changed +17
-4
lines changed Expand file tree Collapse file tree 2 files changed +17
-4
lines changed Original file line number Diff line number Diff line change @@ -28,8 +28,14 @@ exports.transclude = function (el, options) {
2828 if ( _ . isTemplate ( el ) ) {
2929 el = templateParser . parse ( el )
3030 }
31- if ( options && options . template ) {
32- el = transcludeTemplate ( el , options )
31+ if ( options ) {
32+ if ( options . _asComponent && ! options . template ) {
33+ options . template = '<content></content>'
34+ }
35+ if ( options . template ) {
36+ options . _content = _ . extractContent ( el )
37+ el = transcludeTemplate ( el , options )
38+ }
3339 }
3440 if ( el instanceof DocumentFragment ) {
3541 // anchors for block instance
@@ -56,7 +62,6 @@ function transcludeTemplate (el, options) {
5662 if ( ! frag ) {
5763 _ . warn ( 'Invalid template option: ' + template )
5864 } else {
59- options . _content = _ . extractContent ( el )
6065 var replacer = frag . firstChild
6166 if ( options . replace ) {
6267 if (
@@ -121,4 +126,4 @@ function mergeAttrs (from, to) {
121126 to . className = to . className + ' ' + value
122127 }
123128 }
124- }
129+ }
Original file line number Diff line number Diff line change @@ -30,6 +30,14 @@ describe('Content Transclusion', function () {
3030 expect ( el . firstChild . firstChild . textContent ) . toBe ( 'hi' )
3131 } )
3232
33+ it ( 'no template auto content' , function ( ) {
34+ el . innerHTML = '<p>hi</p>'
35+ options . _asComponent = true
36+ mount ( )
37+ expect ( el . firstChild . tagName ) . toBe ( 'P' )
38+ expect ( el . firstChild . textContent ) . toBe ( 'hi' )
39+ } )
40+
3341 it ( 'fallback content' , function ( ) {
3442 options . template = '<content><p>fallback</p></content>'
3543 mount ( )
You can’t perform that action at this time.
0 commit comments