如何使用sails js + vue js模板制作应用程序? [英] How to make a app using sails js + a vue js template?

查看:39
本文介绍了如何使用sails js + vue js模板制作应用程序?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

首先,我来自 PHP + CSS 背景,我过去常常简单地将 CSS 文件放在页眉,将 JS 放在页脚——你知道,经典的东西.现在,我正在尝试制作一个使用 Sails JS 作为后端和一个 Vue JS 模板作为前端的系统.我不知道如何让这些家伙互相交谈".

请,我感谢您的帮助.

我最好的.

解决方案

说到点子上:

  1. .js 文件放在 assets/js 文件夹中,将 .css 文件放在 assets/css 文件夹中.
  2. 默认情况下,Sails 会在 layout.ejs 中注入所有源文件 - 样式和脚本 - 在 /assets 中,查看下面的更多信息.在 config/pipeline.js 上禁用该行为!现在你有 2 个选择,使用布局(如果你想为所有视图提供 .js 文件)或者像这样简单地把它放在你的新视图的末尾(记住将它保存在views/ 文件夹,其中包含 .ejs 并且里面只有一个 body 标签)`:

 <div class="container" id="idforvue">你好!

<!-- vuejs cdn 在这里--><!-- 你的 js href 像 '/js/myjs.js' -->

  1. 为您的视图设置路线!编辑您的 config/routes.js 并插入一个新行 '/' : { view: 'filename'},.

  2. 做一个 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:

  1. Put the .js files in your assets/js folder and your .css in assets/css.
  2. 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 on config/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 the views/ 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>

  1. Setup a route for your view! Edit your config/routes.js and insert a new line '/' : { view: 'filename'},.

  2. 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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆