如何使用sails js + vue js模板制作应用程序? [英] How to make a app using sails js + a vue js template?
问题描述
首先,我来自 PHP + CSS 背景,我过去常常简单地将 CSS 文件放在页眉,将 JS 放在页脚——你知道,经典的东西.现在,我正在尝试制作一个使用 Sails JS 作为后端和一个 Vue JS 模板作为前端的系统.我不知道如何让这些家伙互相交谈".
请,我感谢您的帮助.
我最好的.
说到点子上:
- 将
.js
文件放在assets/js
文件夹中,将.css
文件放在assets/css
文件夹中. - 默认情况下,Sails 会在
layout.ejs
中注入所有源文件 - 样式和脚本 - 在/assets
中,查看下面的更多信息.在config/pipeline.js
上禁用该行为!现在你有 2 个选择,使用布局(如果你想为所有视图提供.js
文件)或者像这样简单地把它放在你的新视图的末尾(记住将它保存在views/
文件夹,其中包含 .ejs 并且里面只有一个 body 标签)`:
<div class="container" id="idforvue">你好!
<!-- vuejs cdn 在这里--><!-- 你的 js href 像 '/js/myjs.js' -->
为您的视图设置路线!编辑您的
config/routes.js
并插入一个新行'/' : { view: 'filename'},
.做一个
sails lift
并访问 `localhost:1337' 以查看你的更改.
更多信息:首先,可以使用很多服务端渲染来解决一些问题.开箱即用的 Sails 使用 EJS.请查看此处.现在,您还想在此处阅读资产文档.不要小看这个框架,太棒了!仔细阅读文档,你应该没问题......
这里的 github 示例:LINK
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.
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
这篇关于如何使用sails js + vue js模板制作应用程序?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!