Unable to load json file from assets/ folder
-
Hi:
I have a JSON file located under theassets
folder. In my page I am trying to access the json file usingimport
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. -
@venkyvb try this
import stocks from 'assets/stock_symbols.json';
-
@sujan-dev Thanks. Had tried that, that doesnt work either. I get an error that
stocks
is undefined. -
How to solve this kind of problem? I need an answer.