Javascript VueJS资源重新加载内容

Javascript VueJS资源重新加载内容,javascript,json,vue.js,vue-resource,Javascript,Json,Vue.js,Vue Resource,资源文件helper/json.json { "content": { "content_body": "<a href='#' v-on:click.prevent='getLink'>{{ button }}</a>", "content_nav": "", } } 输出:不是渲染器 <a href="#" v-on:click.prevent="getLink">{{ button }}</a> 单击按钮时,事

资源文件helper/json.json

{
  "content": {
    "content_body": "<a href='#' v-on:click.prevent='getLink'>{{ button }}</a>",
    "content_nav": "",
  }
}
输出:不是渲染器

<a href="#" v-on:click.prevent="getLink">{{ button }}</a>


单击按钮时,事件不起作用。无法加载数据。

Vue.resource与此问题无关 因为json中的html字符串未编译

下面是一个基于您的示例的小测试:

<body>
    <a href='#' v-on:click.prevent='getLink' v-text="button"></a>
    <div v-el:sample></div>
</body>

var测试=新的Vue({
el:‘身体’,
数据:{
按钮:“Lorem sss”,
},
方法:{
getLink:function(){
var r=Math.floor(Math.random()*(4-1))+1;
此.$set('按钮',['','btn1','btn2','btn3'][r]);
},
getCompiled:function(){
$(this.$els.sample).empty()
var元素=$(this.$els.sample).append(“”);
这个.compile(element.get(0));
$(this.$els.sample).prepend(“编译按钮:

”) } }, 就绪:函数(){ 这个.getCompiled(); } })

Vue.resource与此问题无关 因为json中的html字符串未编译

下面是一个基于您的示例的小测试:

<body>
    <a href='#' v-on:click.prevent='getLink' v-text="button"></a>
    <div v-el:sample></div>
</body>

var测试=新的Vue({
el:‘身体’,
数据:{
按钮:“Lorem sss”,
},
方法:{
getLink:function(){
var r=Math.floor(Math.random()*(4-1))+1;
此.$set('按钮',['','btn1','btn2','btn3'][r]);
},
getCompiled:function(){
$(this.$els.sample).empty()
var元素=$(this.$els.sample).append(“”);
这个.compile(element.get(0));
$(this.$els.sample).prepend(“编译按钮:

”) } }, 就绪:函数(){ 这个.getCompiled(); } })

选中开发工具中的XHR选项卡。另外,尝试
console.log(this)
inside
(resp)=>{
是否正确绑定到Vue实例?检查开发工具中的XHR选项卡。此外,尝试
console.log(this)
inside
(resp)=>{
是否正确绑定到Vue实例?
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();
  }
})