VueJS资源重新加载内容
VueJS Resource reload content
资源文件helper/json.json
{
"content": {
"content_body": "<a href='#' v-on:click.prevent='getLink'>{{ button }}</a>",
"content_nav": "",
}
}
Vue main.js文件
new Vue({
el: 'body',
data: {
text: 'Lorem sss',
},
methods: {
getLink: function(){
this.$http.get('http://localhost/vuejs/helper/json.json').then((resp) => {
this.$set('text', resp.data.content.content_body);
}, (resp) => {
console.log('error');
})
}
}
})
输出:Not Renderer
<a href="#" v-on:click.prevent="getLink">{{ button }}</a>
事件在按钮被点击时不起作用。无法加载数据
资源与这个问题无关因为json中的HTML字符串没有被编译。
这里有一个基于你的例子的小测试:
<body>
<a href='#' v-on:click.prevent='getLink' v-text="button"></a>
<div v-el:sample></div>
</body>
var test = new Vue({
el: 'body',
data: {
button: 'Lorem sss',
},
methods: {
getLink: function(){
var r = Math.floor(Math.random() * (4 - 1)) + 1;
this.$set('button', ['','btn1','btn2','btn3'][r] );
},
getCompiled: function() {
$(this.$els.sample).empty()
var element = $(this.$els.sample).append("<a href='#' v-on:click.prevent='getLink'>{{ button }}</a>");
this.$compile(element.get(0));
$(this.$els.sample).prepend('<p>Compiled button:</p>')
}
},
ready: function() {
this.getCompiled();
}
})
jsfidle
相关文章:
- 内容安全策略:页面's设置阻止加载资源
- 未能在Laravel中加载资源
- Nodejs服务器:加载资源失败:服务器的响应状态为404(未找到)
- 带Jquery的wep API,加载资源失败:服务器响应状态为404(未找到)
- 在服务器上加载资源失败
- 打开 UI5 sap-ui-core.js无法加载资源
- 无法在铬下加载资源!目前不能使用 ajax
- 带有jquery.min.map的Ruby on Rails:未能加载资源状态406
- 我得到了一个“;未能加载资源“;在尝试运行空白离子启动器应用程序时出现Cordova错误
- XMLHttpRequest”;未能加载资源“;使用Safari
- 试图从错误位置加载资源的Rails
- 推特按钮无法加载资源 file://platform.twitter.com/widgets.js
- 处理从 CDN 加载资源失败或缓慢的问题
- 无法加载资源
- 无法加载资源 socket.io
- 捕获由
中的 HTML 标记导致的“无法加载资源”错误 - 无法加载资源:下载多个文件时,Safari 浏览器中的帧加载中断
- Angular JS在href加载资源之前触发ng-click
- 加载资源失败:服务器使用 nodejs 以状态 404(未找到)进行响应
- HTML5 视频 - 开始播放后无法加载资源错误