How to make a app using sails js + a vue js template?

耗尽温柔 提交于 2019-12-22 12:25:12

问题


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:

  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



来源:https://stackoverflow.com/questions/46930202/how-to-make-a-app-using-sails-js-a-vue-js-template

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!