No More Posting New Topics!

If you have a question or an issue, please start a thread in our Github Discussions Forum.
This forum is closed for new threads/ topics.

Navigation

    Quasar Framework

    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search

    Import constants file for entire project to use

    Framework
    2
    2
    347
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • K
      keechan last edited by keechan

      I have a constants.js file where I put all my constants.
      Currently, I just import it on every file as:

      import * as constants from '../scripts/constants.js'
      

      And use them like this:

      constants.SOMEVARIABLE
      

      But it is too cumbersome IMO. Is there a way to import this file for the entire project to use? (Similar to when I want to add my own css, I just added under the css array in quasar.conf.js

      Thanks in advance!

      1 Reply Last reply Reply Quote 0
      • s.molinari
        s.molinari last edited by s.molinari

        You can hook it onto the Vue prototype with a boot file, so that you’d then have this.$consts.SOME-CONSTANT available in the components.

        https://quasar.dev/quasar-cli/cli-documentation/boot-files#Introduction

        Scott

        1 Reply Last reply Reply Quote 0
        • First post
          Last post