Answer the question
In order to leave comments, you need to log in
Is it possible to declare methods and so on by condition?
Hello, I have a question, is it possible to declare a method and so on by condition?
I wrote a slider, for a PC and a sensor, there are touch event handlers and methods for them, which are not used on the PC version. Is it possible to do something like
if(mobile){
touchStart() ...
}
Answer the question
In order to leave comments, you need to log in
What problems?
created() {
if(mobile){
this.touchStart = () => {}
}
}
let touchStart;
if(mobile){
touchStart = function() {}
} else {
touchStart = function() {}
}
export {
touchStart
}
import {touchStart, ...} from './helpers';
methods: {
touchStart,
...
}
const touchMixin = {
methods: mobile ? {
touchStart() {}
} : {
touchStart() {}
}
}
mixins: [touchMixin],
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question