Unable to mount dynamically loaded tags

Asked 1 years ago, Updated 1 years ago, 30 views

I use the following code, which is often used when loading dynamically in javascripts, but I am having trouble with mounting on riot.js. I can't even try the update or callback execution position.The loadscript itself is working, and you can see it added to the DOM.

There are about 30 things to load, and I can write them all on the head, but if possible, I would like to load them dynamically and mount them when I need them.(No, please let me know if you have any questions, such as reading 30 of them.)

 function loadScript(src, callback){
    var head = document.getElementsByTagName('head')[0];
    varscript = document.createElement('script');
    script.src=src;
    script.type="riot/tag";
    head.appendChild(script);
    callback();
}

javascript

2022-09-30 19:54

2 Answers

I was able to do what I wanted to do.While reading the source code diagonally, I found something called virtualDom and understood that I could mount ('*') what was listed per compileScripts beforehand, but not scan anything that wasn't on the list.

test.html

<html>
<head>
<script src="riot+compiler.min.js"></script>
</head>
<body>
<test1></test1>
<test2></test2>
<script type="riot/tag" src="test1.tag">/script>
<script>riot.mount('*');</script>
</body>
</html>

test1.tag

<test1>
 <button onclick='{clicked}'>test</button>
</test1>
This.clicked=function(e){
 US>riot.compile('test2.tag', function(){
  US>riot.mount ('test2')
 })
}

test2.tag

<test2>
<span>{test}</span>
This.test='hello world'
</test2>

I don't know if it's the right way to call rip.compile.This time, I feel that the problem has been solved because I wanted to look into it now to write the code.

http://riotjs.com/ja/guide/compiler/

There was a section called "Access Tag Instances" and it was written properly.


2022-09-30 19:54

I'm sorry for complimenting you, but I think the answer to the question here will be helpful.
riot.mount('*') within window.onload.
I've already tried it, but if it doesn't work, I'm sorry.


2022-09-30 19:54

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.