[英]mithril avoiding to reload image
I am using mithril 0.2.2-rc.1. 我正在使用秘银0.2.2-rc.1。 I saw in the routing documentation : Routing is a system that allows creating Single-Page-Applications (SPA), ie applications that can go from one page to another without causing a full browser refresh.
我在路由文档中看到: 路由是一个系统,它允许创建单页应用程序(SPA),即可以在不导致浏览器完全刷新的情况下从一个页面转到另一个页面的应用程序。
Indeed when I am routing to the same page with different parameter only the part that I want to change is refresh expect this : 事实上,当我路由到不同的参数,只是我想更改刷新预计这一部分在同一个页面:
m("img[src='assets/images/logo.png'][alt=''][width='100']")
I can see in the network communication that the image is reloaded (another GET request). 我可以在网络通信中看到图像已重新加载(另一个GET请求)。
Is there a way to avoid that? 有办法避免这种情况吗?
route.js route.js
m.route.mode = "pathname";
m.route(document.getElementById('app'), '/', {
'/': main,
'/modelling/:level': main
})
It's difficult to see how the two pieces of code fit together, but two things suggest themselves: 很难看到这两段代码是如何组合在一起的,但是有两点说明了自己:
/modelling/x
to /modelling/y
) will result in the entire DOM being regenerated. /modelling/x
到/modelling/y
)也将导致重新生成整个DOM。 You can prevent this behaviour by calling m.redraw.strategy( 'diff' )
in each route component's controller. m.redraw.strategy( 'diff' )
来防止此行为。 If you check the documentation of the m
method you will see that the config
attribute lets you retain elements across redraws. 如果查看
m
方法的文档,您将看到config
属性可让您在重绘之间保留元素。 So this should work for you: 因此,这应该为您工作:
m('img', {config: function persist(el, isInit, context)}) {
context.retain = true;
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.