vue + jquery+ bootstrap

使用 vue简单写的一个页面demo ,用jquery发送ajax请求,bootstrap 组件。

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0, user-scalable=no">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>QA</title>
    <script src="js/vue.min.js"></script>
    <script src="js/jquery.min.js"></script>
    <link href="css/bootstrap.min.css" rel="stylesheet">

</head>

<body>
    <div id="app">
      <div class="container" style="margin-top:100px">
        <div class="row">
          <div class="col-md-6">
  	    <div class="d-grid gap-2">
  		<label for="textarea1" class="form-label">     
                  please input your question:	
  		</label>
                <textarea class="form-control" ref="question_textarea" rows="16">  {{question}}  </textarea>
  	        <button class="btn btn-primary" type="button" v-on:click="inference()">commit</button>
            </div>
          </div>
          <div class="col-md-6">
            <div class="d-grid gap-2">
                  <label  class="form-label">
                    answer :
                  </label>

		
		  <p  class="form-control" v-html="answer" :style="{'white-space': 'pre-line','height':`${p_height}px`}"  rows="16" readonly > </p>
              </div>
            </div>
        </div>  
      </div>  
    </div>
    <script>
        new Vue({
            el: '#app',
            data: {
                question: 'how are you?',
		    answer: '',
		    p_height: 396
            },
	    methods:{
	        inference:function(){
			var that = this
			$.post('/inference',{'question':this.question},function(res){
			   ans_list=res.data
				that.answer=new String(ans_list.join('<br/><br/>'))
			})    
		}
	    },
	    mounted () {
              this.height = this.$refs.question_textarea.clientHeight
            }
        })
    </script>
</body>
</html>

python flask后台服务
 

from flask import Flask, render_template, request, send_file
import os

app = Flask(__name__)
app.jinja_env.variable_start_string = '<<' 
app.jinja_env.variable_end_string = '>>'

@app.route("/")
def index():
    return render_template("home.html")

@app.route("/inference", methods=["GET", "POST"])
def home():
    json_obj = dict()
    if request.method == "GET":
        return render_template("home.html", base_dir=base_dir)
    if request.method == "POST":
        question = request.form['question']
        return {'code':200,"data":question }

@app.route("/js/<filename>", methods=["GET"])
def js(filename):
    return send_file(os.path.join('templates/js/', filename))

@app.route("/css/<filename>", methods=["GET"])
def css(filename):
    return send_file(os.path.join('templates/css/', filename))

if __name__ == "__main__":
    print("server is running .....")
    app.run(host='0.0.0.0', port=5000)

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值