LoginSignup
2
0

More than 5 years have passed since last update.

riot.js tagの存在タイミング

Last updated at Posted at 2018-04-09

on or one('mount',...) で図る。

codeMirrorのようなdocument.bodyに存在していなければフォーマットが崩れる場合、dom生成のタイミングは重要。

<script src="//gnjo.github.io/riot.js"></script>
<h1>dom exist check</h1>
<test></test>
<script type="text/plain" name="cheat-sheet">
this.one this.on this.off this.trigger:
update updated before-mount mount
before-unmount unmount
</script>

riot.tag(
 'test'
 ,`<h3 id={x} onclick={click}>{message}</h3>`
 , function(opts){
   message='click me'
   x='xxx'

   console.log('constructer',document.querySelector('#xxx')) // not join body
   this.one('mount',()=>{
    console.log('mount-ed',document.querySelector('#xxx')) //slave the body
   })
   click=function(ev){
    message = (document.querySelector('#xxx'))?'is':'not'
   }
});

//finally one;
riot.mount('test');

2
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2
0