Skip to content

hitvalley/both-render

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

16 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

both-render

render in server and browser

代码

模板:assets/views/main.tpl

{{title}}
<footer id="id-auth"></footer>
{{hack}}
<script id="id-tpl" type="text/html">
{{author}}
</script>
<script>
(function(){
  let tpl = document.querySelector('#id-tpl').innerHTML;
  let html = vtpl(tpl, {
    author: 'hitvalley'
  });
  document.querySelector('#id-auth').innerHTML = html;
}());
</script>
{{/hack}}

server端运行

{{title}}
<footer id="id-auth"></footer>

client端运行

{{hack}}
<script id="id-tpl" type="text/html">
{{author}}
</script>
<script>
(function(){
  let tpl = document.querySelector('#id-tpl').innerHTML;
  let html = vtpl(tpl, {
    author: 'hitvalley'
  });
  document.querySelector('#id-auth').innerHTML = html;
}());
</script>
{{/hack}}

run

npm start

# 访问:http://localhost:8080

结果

image

About

render in server and browser

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors