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

    Unable to load json file from assets/ folder

    Help
    3
    4
    1823
    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.
    • V
      venkyvb last edited by

      Hi:
      I have a JSON file located under the assets folder. In my page I am trying to access the json file using import statement

      ...
      
      import stocks from '../assets/stock_symbols.json';
      
      // lines omitted here for brevity...
      
      function parseStockSymbolsLocal() {
        return stocks.map(entry => {
          return {
            label: entry.name,
            value: entry.symbol
          };
        });
      }
      
      export default {
        name: 'StockSearch',
      
        data() {
          return {
            stockSymbol: ""
          };
        },
      
        methods: {
          searchStocksLocal(stockSymbol, done) {
            setTimeout(() => {
              done(
                filter(stockSymbol, { field: 'name', list: parseStockSymbolsLocal() })
              );
            }, 1000);
          },
      
          selectedStock(item) {
            this.$q.notify(`Selected suggestion "${item.label}"`);
          }
        }
      };
      

      However looks like the JSON file is not getting loaded.

      The JSON file just contains an array of stock symbols.

      [
        {
          "name": "Agilent Technologies Inc.", 
          "symbol": "A"
        }, 
        {
          "name": "Alcoa Corporation", 
          "symbol": "AA"
        }, 
        {
          "name": "Altaba Inc.", 
          "symbol": "AABA"
        }, 
        {
          "name": "AAC Holdings Inc.", 
          "symbol": "AAC"
        }, 
        {
          "name": "AdvisorShares Dorsey Wright ADR", 
          "symbol": "AADR"
        }
      ]
      

      Any other settings need to make this work? This approach seems to be working in the showcase app.
      Thanks.

      S 1 Reply Last reply Reply Quote 0
      • S
        Sujan Dev @venkyvb last edited by

        @venkyvb try this import stocks from 'assets/stock_symbols.json';

        V 1 Reply Last reply Reply Quote 0
        • V
          venkyvb @Sujan Dev last edited by

          @sujan-dev Thanks. Had tried that, that doesnt work either. I get an error that stocks is undefined.

          1 Reply Last reply Reply Quote 0
          • S
            Stephen last edited by

            How to solve this kind of problem? I need an answer.

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