Collectives™ on Stack Overflow
Find centralized, trusted content and collaborate around the technologies you use most.
Learn more about Collectives
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
Learn more about Teams
as shown in the below posted code, i want to export the function
GISWSCaller
. i am following the tutorial in
this link
, and i want to create something as in the 3rd code snippet in that link.
the problem i am encountring is, for the below posted code, the VS-codes studio can not recognize the code as valid. i mean the same code posted below when pasted into the VS-codes, it becomes colored in whitw as shonw in the screen shot attached.
please let me know how correctly i should export the code posted below.
updated code .vue
:
import { provide } from 'vue';
let res = undefined
export default function GISWSCaller(){
async function fetchURL(params){
console.log("params:",params);
const splitted = params.split(',')
if (splitted.length == 4) {
const response = await fetch('https://xx/xx/getDistanceFromOriginToDestination/' + params)
res = await response.json()
return res
return false
const ctx = {
fetchURL
provide('GISWSContext',ctx)
return fetchURL
img:
–
–
–
–
–
all your code must be inside this parts.
your file is .vue format, and your code is out of the mentions parts.
put your code inside the script tag, or change file extension to .js to resolve this problem.
more information
edited:
src/utils/GISWSCaller.is
let res = undefined
export function useGISWSCaller() {
async function fetchURL(params) {
console.log('params:', params);
const splitted = params.split(',')
if (splitted.length == 4) {
const response = await fetch('https://xx/xx/getDistanceFromOriginToDestination/' + params)
res = await response.json()
return res
return false
const ctx = {
fetchURL
return ctx
src/main.js
import {createApp} from 'vue'
import {useGISWSCaller} from 'GISWSCaller'
const app = createApp({})
const ctx = useGISWSCaller()
app.provide('ctx', ctx)
app.mount('#app');
–
–
–
–
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.