第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號安全,請及時綁定郵箱和手機立即綁定

Vue如何調用webservice

標簽:
C#

首先在asp.net项目中的web.config中加入:

 <system.webServer>
    <httpProtocol>
      <customHeaders>
        <add name="Access-Control-Allow-Methods" value="OPTIONS,POST,GET"/>
        <add name="Access-Control-Allow-Headers" value="x-requested-with,content-type,Accept"/>
        <add name="Access-Control-Allow-Origin" value="*" />
      </customHeaders>
    </httpProtocol>
  </system.webServer>

然后在AppCode中的WebService.cs中加入:

[WebService(Namespace = "http://tempuri.org/")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
[System.ComponentModel.ToolboxItem(false)]
[System.Web.Script.Services.ScriptService]
// 若要允许使用 ASP.NET AJAX 从脚本中调用此 Web 服务,请取消注释以下行。 
// [System.Web.Script.Services.ScriptService]
public class WebService : System.Web.Services.WebService
{
    [WebMethod(Description = "GetUserinfoList")]
    public string GetUserinfoList()
    {
        DataSet ds = null;
        string json = "";
        string sql = "";
        try
        {
            SqlParameter[] paras = new SqlParameter[1];
            paras[0] = new SqlParameter("@today", SqlDbType.VarChar);
            paras[0].Value = "";
            sql = @"select * from Userinfo";
            ds = SqlHelper.ExecuteDataset(getLocalConnection(), CommandType.Text, sql, paras);
            if (ds == null || ds.Tables[0].Rows.Count == 0)
                json = "";
            else
                json = JsonConvert.SerializeObject(ds.Tables[0], new DataTableConverter());
        }
        catch (Exception ex)
        {
            json = "";
        }
        return json;
    }

然后在vue的项目中引入js:

npm install jquery --save

然后在vue.config.js加入:

const webpack = require('webpack')
module.exports = {
  devServer: {
    overlay: {
      warnings: false,
      errors: false
    }
  },
  lintOnSave: false,
  publicPath: './',
  chainWebpack: config => {
    config.plugin('provide').use(webpack.ProvidePlugin, [{
      $: 'jquery',
      jquery: 'jquery',
      jQuery: 'jquery',
      'window.jQuery': 'jquery'
    }])
  }
}

然后在页面中这么来使用:

<template>
    <el-table
            :data="userData"
            border
            style="width: 100%">
        <el-table-column
                prop="UserId"
                label="Id"
                width="180">
        </el-table-column>
        <el-table-column
                prop="UserName"
                label="姓名"
                width="180">
        </el-table-column>
        <el-table-column
                prop="Address"
                label="地址">
        </el-table-column>
    </el-table>
</template>

<script>
    import {tqData,getUser} from '@/network/networks'
    import $ from 'jquery'
    import axios from "axios";
    export default {

        mounted() {
            var _this = this;
            $.ajax({
                    type: "post",
                    url: "http://localhost:57651/WebService.asmx/GetUserinfoList",    //接口地址,后面加上 /方法名即可
                    contentType: "application/json",
                    dataType: "json",
                    success: function (inf) {

                        _this.$nextTick(() => {
                            _this.userData = JSON.parse(inf.d);    //将获取的JSON字符串转化成JSON对象
                            console.log("<<<111");
                            console.log(this.userData);
                            _this.itemkey = Math.random();
                        });
                    },
                    error: function () {
                        alert("获取数据失败!");
                    }
            });
        },
        methods:{
        },
        data() {
            return {
                itemkey:'',
                userData: []
            }
        }
    }
</script>


點擊查看更多內容
TA 點贊

若覺得本文不錯,就分享一下吧!

評論

作者其他優(yōu)質文章

正在加載中
  • 推薦
  • 評論
  • 收藏
  • 共同學習,寫下你的評論
感謝您的支持,我會繼續(xù)努力的~
掃碼打賞,你說多少就多少
贊賞金額會直接到老師賬戶
支付方式
打開微信掃一掃,即可進行掃碼打賞哦
今天注冊有機會得

100積分直接送

付費專欄免費學

大額優(yōu)惠券免費領

立即參與 放棄機會
微信客服

購課補貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號

舉報

0/150
提交
取消