问题
First, i came from a PHP + CSS background, where i used to simply put the CSS files on header and JS on footer -- you know, classic stuff. Now, I`m trying to make a system using Sails JS as backend and a Vue JS template as frontend. I have no idea how to make this guys "talk to each other".
Please, I appreciate any help.
My best.
回答1:
Right on the point:
- Put the
.js
files in yourassets/js
folder and your.css
inassets/css
. - By default Sails inject in your
layout.ejs
all source files - styles and scripts - inside/assets
, take a look bellow for more information. Disable that behavior onconfig/pipeline.js
! Now you have 2 choices, use a layout (if you want to serve your.js
file for all views) or simply put it in the end of your new view like this (remember to save it in theviews/
folder with .ejs and only a body tag inside)`:
<body>
<div class="container" id="idforvue">
Hello!
</div>
<!-- vuejs cdn here -->
<!-- your js href like '/js/myjs.js' -->
</body>
Setup a route for your view! Edit your
config/routes.js
and insert a new line'/' : { view: 'filename'},
.Do a
sails lift
and access `localhost:1337' to see your changes.
More infos: First of all, you can use a lot of server-side rendering to solve some problems. Out of the box Sails uses EJS. Take a look here. Now you also want to read the Assets docs here. Dont underestimate this framework, it is awesome! Read the docs carefully and you should be fine...
EDIT: github example here: LINK
来源:https://stackoverflow.com/questions/46930202/how-to-make-a-app-using-sails-js-a-vue-js-template