Created
March 12, 2020 20:11
-
-
Save georgechang/6cadd9853f87f25f8843c522bf8ea677 to your computer and use it in GitHub Desktop.
conditional Vue initialization to accommodate for Experience Editor
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// check if this is Experience Editor | |
if (typeof Sitecore !== typeof undefined && | |
typeof Sitecore.PageModes !== typeof undefined && | |
typeof Sitecore.PageModes.PageEditor !== typeof undefined) { | |
Sitecore.PageModes.PageEditor.onLoadComplete.observe(() => { | |
// add v-pre to all placeholder elements | |
document | |
.querySelectorAll("code[type='text/sitecore']") | |
.forEach(ph => ph.setAttribute('v-pre', '')); | |
// then initialize Vue | |
new Vue({ | |
el: '#app' | |
}); | |
}); | |
} else { | |
// initialize Vue directly if not in EE | |
new Vue({ | |
el: '#app' | |
}); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment