本文整理匯總了TypeScript中vue-property-decorator.Watch函數的典型用法代碼示例。如果您正苦於以下問題:TypeScript Watch函數的具體用法?TypeScript Watch怎麽用?TypeScript Watch使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。
在下文中一共展示了Watch函數的5個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的TypeScript代碼示例。
示例1: imageUpdater
@Watch("image", { immediate: true })
imageUpdater() {
let metaImage = document.getElementById("meta-image") as HTMLMetaElement;
if (this.image) {
metaImage.content = this.image;
} else {
metaImage.content = window.location.origin + "/img/only-logo.png";
}
}
示例2: descriptionUpdater
@Watch("description", { immediate: true })
descriptionUpdater() {
let metaDescription = document.getElementById(
"meta-description"
) as HTMLMetaElement;
let metaOGDescription = document.getElementById(
"meta-og-description"
) as HTMLMetaElement;
metaOGDescription.content = this.description;
metaDescription.content = this.description;
}
示例3: metaUpdator
@Watch("$route.fullPath", { immediate: true })
metaUpdator() {
let link = document.getElementById("canonical-link") as HTMLLinkElement;
let metaUrl = document.getElementById("meta-url") as HTMLMetaElement;
let metaType = document.getElementById("meta-type") as HTMLMetaElement;
let metaImage = document.getElementById("meta-image") as HTMLMetaElement;
link.href = document.location.href;
metaUrl.content = document.location.href;
if (this.$route.name === routes.video.name) {
metaType.content = "video.other";
metaImage.content = `https://img.youtube.com/vi/${
this.$route.params[routes.video.params.id]
}/hqdefault.jpg`;
} else {
metaType.content = "website";
metaImage.content = window.location.origin + "/img/only-logo.png";
}
}
示例4: OnRouteChange
@Watch('$route')
OnRouteChange() {
if (this.device === DeviceType.Mobile && this.sidebar.opened) {
AppModule.CloseSideBar(false);
}
}
示例5: titleUpdater
@Watch("title", { immediate: true })
titleUpdater() {
document.title = this.title ? `vTyoob - ${this.title}` : "vTyoob";
let metaTitle = document.getElementById("meta-title") as HTMLMetaElement;
metaTitle.content = document.title;
}