Vue + element-ui 后台数据返回前台显示

在原来ASP.NET 网站项目上做的扩展,完整的Vue项目用不了,只能用Vue + element-ui + axios。

前台C#:

刷新

            
            
           
           
           
                
             

             
              
            
          

后台:

/// 
        /// 获取表单状态列表
        /// 
        /// 
        [WebMethod]
        public static string getSealyInfo(string content)
        {
            Connection connection = new Connection();
            SqlConnection conn = connection.getConnection();
           // string sql = "select id as 'index',CONVERT(varchar(100), ApplyDate, 23) as date  , ApplyUser as name,  IsTake as checkstate, ApplyFileName as reviewprocess from SealApplyTbl  ";
            //0:用印申请单
            string sql = "select  Form_ID as 'index', CONVERT(varchar(100), ApplyDate, 23) as date , ApplyUserName as name,case Status when '0' then '已提交' when '1' then '审核中' when '2' then '已审核' when '3' then '已驳回' ELSE '已作废' END as checkstate,case Status when '0' then '单据已提交,等待审核' when '1' then '单据审核中' when '2' then '单据已审核' when '3' then '单据已驳回' ELSE '单据已作废' END as reviewprocess from CheckStatusTest where Form_Type=0";
            //强大的SqlDataAdapter 
            System.Data.SqlClient.SqlDataAdapter adapter = new SqlDataAdapter(sql, conn);

            DataSet ds = new DataSet();
            //Fill 方法会执行一系列操作 connection.open command.reader 等等
            //反正到最后就把 sql语句执行一遍,然后把结果集插入到 ds 里.
            adapter.Fill(ds);

            DataTable dt = ds.Tables[0];
            string json = "";
            //JsonConvert.SerializeObject(dt, Formatting.Indented);//查询结果转json
            if (dt.Rows.Count > 0)
            {
               // json  = JsonConvert.SerializeObject(dt);
                json = ToJsonUtil.CreateJsonStr(dt);
            }
            return json;
        }

Vue.js:

 //刷新
      refreshForm() {
        var _this4 = this;
        var senddata = new Object();
        axios.post('Main.aspx/getSealyInfo',{'content': JSON.stringify(senddata)})
        .then(function(resp){
                 if(resp.status === 200 && resp.statusText === "OK"){
                      //将后台传过来的json字符串转换成数组
                      _this4.tableData=eval('(' + resp.data.d + ')');
                  }
                }).catch(resp => {
                    _this4.$message({
                            type: 'info',
                            message: '请求失败!'+resp.status+','+resp.statusText
                        }); 
            });
      }

主要是这句:_this4.tableData=eval('(' + resp.data.d + ')');

2.json字符串转换为json对象

1、使用eval

result = eval('(' + jsonstr + ')'); // jsonstr是json字符串

参考:https://blog.csdn.net/qq_42345108/article/details/101696032

你可能感兴趣的:(vue,element-ui,c#,vue.js)