How to create a vue.js app in Visual Studio Code - vue.js

Just starting with vue.js. I am using Visual Studio Code, and have followed all the instructions for using VS Code with the Volar extension. I can see from the source files that the sample project includes a 'hello world' page (HelloWorld.vue). But when I run index.html I just get a blank screen , because of a CORS error (see below).
I haven't changed any code from the installed sample, so it appears that the vuejs.org instructions are not complete.
index.html:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<link rel="icon" href="/favicon.ico">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Vite App</title>
</head>
<body>
<div id="app">
</div>
<script type="module" src="/src/main.js"></script>
</body>
</html>
and main.js:
import { createApp } from 'vue'
import App from './App.vue'
import './assets/main.css'
createApp(App).mount('#app')
So what do I need to do to make use of the example .vue components?
The Chrome console shows a CORS problem:
Access to script at 'file:///C:/Users/quilk/Documents/testvue/main.js' from origin 'null' has been blocked by CORS policy: Cross origin requests are only supported for protocol schemes: http, data, isolated-app, chrome-extension, chrome, https, chrome-untrusted.

To have an easy and simple time working with Vue, I recommend following the official steps:
npm init vue#latest
cd <your-project-name>
npm install
npm run dev
For CORS, you need to fix it on your backend/service dashboard. More details are available here.

Related

Vue app works when served via npm's serve function, but blank page when served via golang net/http package

I have a Vuejs app that I'm trying to serve via a Golang backend that will also serve the app's API.
When I build and run the Vuejs via "npm run build" and "serve -s dist" and go to the static server's location, everything loads up fine. But when I try to load it through the Golang backend, even though the index.html loads (as verified by checking the source in the browser), I just get a blank white page.
Is this approach not possible? Am I going about this all wrong?
Here is how I am serving the "dist" folder via Golang.
http.Handle("/", http.StripPrefix("/", http.FileServer(http.Dir(htmlFolder+"/dist/"))))
My index.html file:
<!DOCTYPE html>
<html lang=en>
<head>
<meta charset=utf-8>
<meta http-equiv=X-UA-Compatible content="IE=edge">
<meta name=viewport content="width=device-width,initial-scale=1">
<link rel=icon href=/favicon.ico>
<title>TestApp</title>
<link href=/css/app.52c62e82.css rel=preload as=style>
<link href=/css/chunk-vendors.7724753e.css rel=preload as=style>
<link href=/js/app.9a3ab992.js rel=preload as=script>
<link href=/js/chunk-vendors.6808fe3a.js rel=preload as=script>
<link href=/css/chunk-vendors.7724753e.css rel=stylesheet>
<link href=/css/app.52c62e82.css rel=stylesheet>
</head>
<body>
<noscript>
<strong>We're sorry but TestApp doesn't work properly without JavaScript enabled. Please enable it to continue.</strong>
</noscript>
<div id=app></div>
<script src=/js/chunk-vendors.6808fe3a.js></script>
<script src=/js/app.9a3ab992.js></script>
</body>
</html>
Edit:
I also tried using gorilla/mux example here:
https://blog.questionable.services/article/vue-react-ember-server-golang/
And here is my "dist"'s folder structure.
press F12 on your browser and go to console tab to view the error
Turns out I just needed to empty my caches. I was using FN5 when refreshing assuming that that would reload it.

How to Use Feather Icons on Laravel through Laravel Mix, NPM

I am trying to use feather icons in laravel enviroment, I thought i would do it through npm. Can someone help me understand how this work as I couldnt get it working. I am very new to working with packages.
I installed
npm install feather-icons --save
then I added const feather = require('feather-icons') to my resource/app.js,
then I run "npm run dev"
How would i display the icons listed at this website (say cirlce) on my pages?
Is what I did above correct?
Thanks
Yes what you did is correct. Follow the steps for adding icon to your project.
Add feather.replace() method in same app.js file.
Link generated file to your layout or page it should be stored in public/js by default so the script tag is looks like (assuming you using it in Laravel Blade)
<script src="{{ asset('js/app.js') }}"></script>
Or if you are using Laravel Mix
<script src="{{ mix('js/app.js') }}"></script>
Add desired icon to your markup
<h1><i data-feather="circle"></i>Hello World</h1>
it should work fine. alternatively you can use directly by linking to CDN.
<!DOCTYPE html>
<html lang="en">
<title></title>
<script src="https://unpkg.com/feather-icons"></script>
<body>
<!-- example icon -->
<i data-feather="circle"></i>
<script>
feather.replace()
</script>
</body>
</html>
1.resource/assets/js/app.js
=================================
2.paste this code
=================================
require('./bootstrap');
//integrate
const feather = require('feather-icons')
//call
feather.replace();
============================================
3.write on terminal
============================================
npm install feather-icons
npm run dev
=======================================
4.in blade file
=======================================
<!DOCTYPE html>
<html lang="en">
<title></title>
<body>
<!-- example icon -->
<i data-feather="circle"></i>
</body>
</html>

Can't deploy Vue app in production

I'm trying to deploy a Vue app in production. After executing the command "npm run build" I copied "index.html" and "dist" into my apache root directory. When I access to my website, the next mistake appears:
external "vue-axios":1 Uncaught ReferenceError: vue is not defined
Do you know if I have to do an additional step before deploying my app?
PX: This app works properly by using "npm run dev"
So it looks like the reason you are getting Uncaught ReferenceError: vue is not defined is likely due to the fact that you are requiring your source code bundle before you are requiring Vue.js. (Assuming you don't have vue bundled into your source)
So when the browser hits <script src="/dist/build.js"></script>, any code that relies on vue is going to fail.
<!DOCTYPE html> <html lang="es"> <head> <meta charset="utf-8"> <title>soporte_7x24</title> <link rel="stylesheet" href="maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/…; crossorigin="anonymous"> </head> <body> <div id="app"></div> <script src="/dist/build.js"></script> <script src="cdnjs.cloudflare.com/ajax/libs/vue/1.0.18/…;"/> </body> </html>
Change the order of <script src="/dist/build.js"></script> so that it is after <script src="cdnjs.cloudflare.com/ajax/libs/vue/1.0.18/…;"/>

Vue.js with System.js how to run a local example

I would like to run locally a Vue.js/System.js demo app I just got recently, never used System.js before (and I'll not...)
I only want to run this demo, before switching it to webpack...
There is no npm script (so no install, no run dev)
How should I run it to display in my local browser?
Anything to do before running? (there is no documentation on it..)
demo
app
components
About
App
..
index.js
routes
Home
...
index.js
style
main.css
assets
home
...
...
documentation
...
libs
favicon.ico
index.html
readme.html
UPDATE
Here is the system.config:
System.config({
defaultJSExtensions: true
, map: {
'app': './app'
, 'js': '/libs/js'
, 'style': '/libs/css'
, 'theme': '/app/theme'
, 'babel': '/libs/js/babel-core'
, 'components': '/app/components',
'routes': '/app/routes',
},
transpiler: 'babel'
, meta: {
'js/*.js': {
format: 'global'
}
}
});
System.import('/app/index.js');
And the index.html:
<!doctype html>
<html class="no-js" lang="en">
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="author" content="BelosTemas">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Test template</title>
<link rel="shortcut icon" type="image/png" href="favicon.ico" />
<link rel="stylesheet" href="./app/style/main.css" id="theme-stylesheet">
</head>
<body>
<div id="app">
<app></app>
</div>
<!-- system -->
<script src="/libs/js/system.js"></script>
<script src="/app/system.config.js"></script>
</body>
</html>
UPDATE 2
I changed the script src paths in the index.html relative paths (src='./)
now the script file is located .. but it's not executed correctly, CORS related issue ..
Error:
system.js:5 Failed to load file:///app/index.js: Cross origin requests
are only supported for protocol schemes: http, data, chrome,
chrome-extension, https.
I solved it , installing a lightweight web server
npm install -g live-server
then in the console, going to my app directory, I just run it
live-server
default browser is open with http://localhost:8080
bonus : hot reloading !

Got console error `unexpected token <` from sign in page (using keystonejs 4.0 beta4)

I've added keystone to my existing MERN server with webpack. Server started with no error.
However, when I try to access /keystone/signin (which redirected by /keystone) it gives a blank page and console error Uncaught SyntaxError: Unexpected token < from signin?from=/keystone/js/packages.js:1 and signin?from=/keystone/js/signin.js:1
The content in signin.js is
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="initial-scale=1.0,user-scalable=no,maximum-scale=1,width=device-width">
<meta http-equiv="x-ua-compatible" content="ie=edge">
<title>Sign in to OneCharge</title>
<link rel="stylesheet" href="/keystone/styles/keystone.min.css">
<link rel="shortcut icon" href="/favicon.ico" type="image/x-icon">
</head>
<body>
<div id="signin-view"></div>
<script>
var Keystone = {"adminPath":"/keystone","brand":"My Site","csrf":{"header":{"x-csrf-token":"vIRAZlZwZae640a645fd60ed9e8ca9911111a05ce088c8095c"}},"from":"/keystone/js/signin.js","userCanAccessKeystone":false};
</script>
<script src="/keystone/js/packages.js"></script>
<script src="/keystone/js/signin.js"></script>
</body>
</html>
Any hints to solve that could help.
I found a solution to the problem, answering my own question here.
Turns out following the guide here doesn't work for me How to add keystone to an existing express app.
After looking up the code from keystone repository. I found a test project that have everything I need and maybe other people who want to use keystone.
I followed the configuration from the test project repo and work like a charm!