本文整理匯總了TypeScript中vue.mixin函數的典型用法代碼示例。如果您正苦於以下問題:TypeScript mixin函數的具體用法?TypeScript mixin怎麽用?TypeScript mixin使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。
在下文中一共展示了mixin函數的10個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的TypeScript代碼示例。
示例1: function
}
})()
Vue.mixin({
created: function () {
//console.log('mixin hook created called')
},
compiled: function () {
if ($ && $.parser){
$.parser.parse(this.$el);
}
},
attached:function(){
//console.log("attached");
},
dettached:function(){
//console.log("dettached");
},
destroy:function(){
//console.log("called destroyed");
}
});
//e.g.
// new Vue({
// el:'#app',
// data:{
示例2: function
registerMixins: function () {
for (var i = 0; i < mixins.length; i++) {
Vue.mixin(mixins[i]);
}
},
示例3: function
const factory = function(Component: Function, options?: any): void {
Vue.mixin(BuildOptions(Component, options) as any)
}
示例4: require
Vue.use(Element, { locale: elementLocale });
// Register global directives
require('./common/views/directives');
// Register global components
require('./common/views/components');
require('./common/views/widgets');
// Register global filters
require('./common/views/filters');
Vue.mixin({
destroyed(this: any) {
if (this.$el.parentNode) {
this.$el.parentNode.removeChild(this.$el);
}
}
});
/**
* APP ENTRY POINT!
*/
console.info(`Misskey v${version} (${codename})`);
console.info(
'%c%i18n:common.do-not-copy-paste%',
'color: red; background: yellow; font-size: 16px; font-weight: bold;');
// BootTimer解除
window.clearTimeout((window as any).mkBootTimer);
示例5: api
const launch = (router: VueRouter, api?: (os: MiOS) => API) => {
os.apis = api ? api(os) : null;
//#region Dark/Light
Vue.mixin({
data() {
return {
_unwatchDarkmode_: null
};
},
mounted() {
const apply = v => {
if (this.$el.setAttribute == null) return;
if (v) {
this.$el.setAttribute('data-darkmode', 'true');
} else {
this.$el.removeAttribute('data-darkmode');
}
};
apply(os.store.state.device.darkmode);
this._unwatchDarkmode_ = os.store.watch(s => {
return s.device.darkmode;
}, apply);
},
beforeDestroy() {
this._unwatchDarkmode_();
}
});
os.store.watch(s => {
return s.device.darkmode;
}, v => {
if (v) {
document.documentElement.setAttribute('data-darkmode', 'true');
} else {
document.documentElement.removeAttribute('data-darkmode');
}
});
//#endregion
Vue.mixin({
data() {
return {
os,
api: os.api,
apis: os.apis
};
}
});
const app = new Vue({
store: os.store,
router,
render: createEl => createEl(App)
});
os.app = app;
// マウント
app.$mount('#app');
return [app, os] as [Vue, MiOS];
};
示例6: created
Vue.mixin({
created() {
const vm = this;
let obs = vm.$options.subscriptions;
if (typeof obs === "function") {
obs = obs.call(vm);
}
if (obs) {
const keys = Object.keys(obs);
keys.forEach(key =>
(Vue as any).util.defineReactive(
vm,
key,
undefined /* val */,
null /* customSetter */,
true /* shallow */
)
);
vm._subscriptions = keys.map(key => {
return (obs[key] instanceof Observable
? obs[key]
: of(obs[key])
).subscribe(value => (vm[key] = value));
});
}
},
beforeDestroy() {
if (this._subscriptions) {
this._subscriptions.forEach(handle => handle.unsubscribe());
}
}
});
示例7: require
import Vue from 'vue';
import VeeValidate from 'vee-validate';
Vue.use(VeeValidate);
const $style: any = require('identity-obj-proxy');
(HTMLCanvasElement as any).prototype.getContext = () => {
return;
};
(global as any).CLIENT = true;
(global as any).SERVER = true;
(global as any).TEST = true;
Vue.config.productionTip = false;
Vue.mixin({
created() {
this.$style = $style;
},
});
示例8: created
if (title) {
const target = __SERVER__ ? vm.$ssrContext : document
target.title = `${TITLE} | ${title}`
}
}
Vue.mixin(
__SERVER__
? {
created() {
setTitle(this)
},
}
: {
watch: {
'$t.locale'() {
setTitle(this)
},
'$tt.loading'(loading) {
if (!loading) {
setTitle(this)
this.$forceUpdate()
}
},
},
mounted() {
setTitle(this)
},
},
)
示例9: get
Object.defineProperties(Vue.prototype, {
$bus: {
get() { return this.$root.bus; }
},
$authenticated: {
get() { return this.$root.authenticated; },
set(a) { this.$root.authenticated = a; }
}
});
// TODO inject at a module level...?
// AudioContext Mixin: all Components will have access to AudioContext
Vue.mixin({
data() {
return { context };
}
});
// Global Components (inlets / outlets)
Vue.component('inlets', inlets);
Vue.component('outlets', outlets);
new Vue({
store,
data: {
bus: new Vue(),
authenticated: false
},
示例10: Vue
import Vue from "vue";
import VueRouter from "vue-router";
import AsyncComputed from 'vue-async-computed';
import { router } from './router';
import GlobalMixin from './GlobalMixin';
import genericAttr from './attrs/genericAttr.vue';
import "./filters/various";
import "./directives/various";
import "./directives/validators";
import "./directives/Bootstrap";
import "./directives/typeahead";
Vue.mixin(GlobalMixin);
Vue.use(VueRouter)
Vue.use(AsyncComputed)
Vue.component('genericAttr', genericAttr); // make it global to break circular dependency
new Vue({
router
}).$mount(".page");