Answer the question
In order to leave comments, you need to log in
How to combine node and vue?
Help who knows. I have a set of files (see the screenshot) . I'm wondering how you can connect vue through browserify to a nodeJs project. In app.js simple server creation (express)
var express = require('express'),
bodyParser = require('body-parser'),
app = express();
app.use( bodyParser.urlencoded({ extended: true }) );
app.use( bodyParser.json() );
var post = [
{
title: 'my first post',
status: 'low'
},
{
title: 'my second post',
status: 'low'
}
]
app.get( '/', function(req, res){
res.render('index.vue', post);
} );
app.listen(3000, function(){
console.log('This server working on 3000 port');
});
. Answer the question
In order to leave comments, you need to log in
Why does the node need to render the View?
This is the front, and the node is the back.
The node returns data and an "empty" page with app.js connection
This is all the node has to do.
Install https://www.npmjs.com/package/vue-template-compiler
npm i -S vue-template-compiler
Patch require:
'use strict';
const fs = require('fs');
const compiler = require('vue-template-compiler');
require.extensions['.vue'] = (module, filename) => {
let file = fs.readFileSync(filename, 'utf8');
let {script, template} = compiler.parseComponent(file);
let {render, staticRenderFns} = compiler.compile(template.content);
let result = `(function(){'use strict';${script.content}})();Object.assign(module.exports,{render:function(){${render}},staticRenderFns:[${staticRenderFns.map(code => {
return `function(){${code}}`;
}).join(',')}]});`;
module._compile(result, filename);
};
new Vue(require('./App.vue'))
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question