Skip to content

Instantly share code, notes, and snippets.

@georgechang
Created March 12, 2020 20:11
Show Gist options
  • Save georgechang/6cadd9853f87f25f8843c522bf8ea677 to your computer and use it in GitHub Desktop.
Save georgechang/6cadd9853f87f25f8843c522bf8ea677 to your computer and use it in GitHub Desktop.
conditional Vue initialization to accommodate for Experience Editor
// 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