Vue ergodic problem

problem description

I use jquery to get the data to assign data values to Vue, and the assignment is successful. But no data is displayed using v-for traversal.

the environmental background of the problems and what methods you have tried

Vue+bootstrap+jquery

related codes

/ / Please paste the code text below (do not replace the code with pictures)
var chara = new Vue ({

el:"-sharpcontainer",
data:{
    items:"",
},

})
$(function () {

$.post(
    "/Project_web/chara/getAllData",
    function(data){
        var json = JSON.stringify(data.result);
        chara.items = json;
        alert(chara.items);
    },
    "json"    
)

})
this is the js code

here is the code for the jsp page
< tbody >

<tr v-for="item in items">
<td>{{item.id}}</td>
<td>{{item.charName}}</td>
<td>{{item.charType}}</td>
<td>{{item.charDescrible}}</td>
<td>{{item.charStatus}}</td>
<td></td>
</tr>

< / tbody >

what result do you expect? What is the error message actually seen?

the display effect is as follows:

clipboard.png

clipboard.png

May.02,2021

Let the initial value of items be consistent with the value of your callback. An empty object is assigned to an object, and an empty array is assigned to an array

then, vue has its own lifecycle hook, so don't use jquery with vue

.
 var chara = new Vue({
    el: "-sharpcontainer",
    data: {
      items: [],
    },
    created() {
      $.post(
        "/Project_web/chara/getAllData",
        function(data){
          var json = JSON.parse(data.result)
          chara.items = json;
          alert(chara.items);
        },
        'json'
      )
    },
  })

chara.items = json; should be changed to data.result. What v-for wants is an array. If you give a string (after JSON.stringify), it's obviously wrong

.
$.post(
    "/Project_web/chara/getAllData",
    function(data){
        chara.items = data.result;
    },
    'json'    
)
el:"-sharpcontainer",
data:{
    items:[],
},

in addition, instead of using jquery with vue, use axios to fetch data. This is a lot of appropriate

.
Menu