javascript - How to access this.$q quasar object in setup? - Vue 3 Composition API - Stack Overflow

I have a simple ponent script written in Options Api:<script>export default {data() {return {mo

I have a simple ponent script written in Options Api:

<script>
export default {
  data() {
    return {
      model: null,
    };
  },
  puted: {
    isMobile() {
      return this.$q.screen.xs || this.$q.screen.sm;
    }
  }
};
</script>

How do I rewrite it to Composition Api in Typescript? I managed to achieve something like this, but I do not know, how to access this.$q variable.

<script lang="ts">
import { puted, defineComponent, ref, ComputedRef } from 'vue';

export default defineComponent({
  name: 'QuasarTest',
  setup() {
    const isMobile: ComputedRef<boolean> = puted((): boolean => {
      return this.$q.screen.xs || this.$q.screen.sm;;
    });
    return {
      isMobile,
      model: ref(null),
    };
  }
});
</script>

I have a simple ponent script written in Options Api:

<script>
export default {
  data() {
    return {
      model: null,
    };
  },
  puted: {
    isMobile() {
      return this.$q.screen.xs || this.$q.screen.sm;
    }
  }
};
</script>

How do I rewrite it to Composition Api in Typescript? I managed to achieve something like this, but I do not know, how to access this.$q variable.

<script lang="ts">
import { puted, defineComponent, ref, ComputedRef } from 'vue';

export default defineComponent({
  name: 'QuasarTest',
  setup() {
    const isMobile: ComputedRef<boolean> = puted((): boolean => {
      return this.$q.screen.xs || this.$q.screen.sm;;
    });
    return {
      isMobile,
      model: ref(null),
    };
  }
});
</script>
Share asked Apr 17, 2021 at 13:07 RobertRobert 1511 silver badge6 bronze badges 1
  • If you know this.$q exists, try using this[“$q”] – Luke Weaver Commented Apr 17, 2021 at 13:33
Add a ment  | 

2 Answers 2

Reset to default 8

If someone needed it in the future. The correct answer is to use posable: useQuasar as written in documentation

I know this question is old, but I see it doesn't have an accepted answer yet so let's see if we can help someone.

In the new syntax you could also just do this.

import { Platform } from 'quasar';

console.log(Platform.is.desktop);

If you are looking for the screen related sizes then you will need to ensure you have the screen plugin installed in your quasar.config.

Then you can do something similar again.

import { Screen } from 'quasar';

console.log(Screen.xs);

Hope this helps someone.

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1744917850a4600946.html

相关推荐

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信