<lable>分类情况</lable>
<select v-model="content.tid">
<option v-for="type in types" :value="type.id" :key="type.id">
{{type.name}}
</option>
</select>

  

 
总结的很到位

vue select下拉框绑定默认值:

首先option要加value值,以便v-model可以获取到对应选择的值

一、当没有绑定v-model,直接给对应的option加selected属性

二、当给select绑定了v-model的值的时候,要给v-model绑定的data值里写默认值

<template>
<div id ="learn-insert">
<h1>新增学习记录</h1>
<form v-if="!submmited">
<p>学习内容标题</p>
<input type="text" v-model="content.desc" required /> <p>学习详细内容</p>
<textarea type="text" v-model="content.details" required></textarea> <p>分类情况</p>
<select v-model="content.tid">
<option v-for="type in types" :value="type.id" :key="type.id">
{{type.name}}
</option> </select> <button v-on:click.prevent="post">添加学习内容</button>
</form> <div v-if="submmited" >
<h3>亲的学习内容已经发布成功</h3>
</div> <div id="preview">
<h3>内容概览</h3>
<p> 内容描述: {{content.desc}}</p>
<p> 内容详细描述: {{content.details}}</p>
<p> 内容详细描述: {{content.tid}}</p>
</div> </div>
</template> <script>
export default {
data() {
return {
content:{
id:"",
tid:"1",
uid:"",
datetime:"",
desc:"",
details:""
},
types:[],
submmited: false,
id:"1"
}
},
methods: {
post: function(){
this.$http.post('http://localhost:8085/content/add', this.content)
.then((data) =>{
console.log(data);
console.log(this.submmited);
this.submmited= true;
console.log(this.submmited);
}); } },
created(){
this.$http.get('http://localhost:8085/type/showall', true)
.then(function(response){
this.types=response.data;
console.log(this.types);
})
//,this.content.id=this.types[0].id }
} </script> <style scoped>
/*
#learn-insert *{
box-sizing: border-box;
} #learn-insert{
margin: 20px auto;
max-width: 600px;
padding: 20px;
}
*/
label{
display: block;
margin: 20px 0 10px;
} input[type="text"],textarea,select{
display: block;
width: 100%;
padding: 8px;
} textarea{
height: 200px;
} #checkboxes label{
display: inline-block;
margin-top: 0;
} #checkboxes input{
display: inline-block;
margin-right: 10px;
} button{
display: block;
margin: 20px 0;
background: crimson;
color: #fff;
border: 0;
padding: 14px;
border-radius: 4px;
font-size: 18px;
cursor: pointer;
} #preview{
padding: 10px 20px;
border: 1px dotted #ccc;
margin: 30px 0;
} h3{
margin-top: 10px;
}
</style>

  

VUE 单选下拉框Select中动态加载 默认选中第一个的更多相关文章

  1. 下拉框select中option居中样式

    下拉框select中option居中样式 text-align:center;text-align-last:center;

  2. jquery+html三级联动下拉框及详情页面加载时的select初始化问题

    html写的三个下拉框,如下: <select name="ddlQYWZYJ" id="ddl_QYWZYJ" class="fieldsel ...

  3. 一个简单的适用于Vue的下拉刷新,触底加载组件

    一个简单的适用于Vue的上拉刷新,触底加载组件,没有发布npm需要时直接粘贴定制修改即可 <template> <div class="list-warp-template ...

  4. mvvm模式下在WPF项目中动态加载项目的程序集和类

    在mvvm模式的wpf项目中有个需求需要去加载解决方案的程序集,并且根据程序集去动态加载当前程序集的类,做成下拉框形式. 效果: //全局定义 private ComboBox abList= nul ...

  5. vue获取下拉框select的值

    1.我写的是循环遍历,然后获取id :value="v.id"这就是获取的id然后打印就可以获取id了

  6. 【jQuery获取下拉框select、单选框radio、input普通框的值和checkbox选中的个数】

    radio单选框:name属性相同 <input type="radio" id="sp_type" name="p_type" va ...

  7. struts2 jsp表单提交后保留表单中输入框中的值 下拉框select与input

    原文地址:struts2 jsp表单提交后保留表单中输入框中的值 下拉框select与input jsp页面 1     function dosearch() {2         if ($(&q ...

  8. JQuery操作下拉框 select

    要实现这种效果: html代码 1<script src="js/jquery-1.7.2.min.js"></script> 2 <table> ...

  9. vue获取下拉框值

    vue获取下拉框的值,用vue-modle,只有点击下拉框的值才会赋值到下拉框中,初始时下拉框没有数据,而改用$event就不会出现这样的问题,下面看代码以及图解: v-model解决方式: < ...

随机推荐

  1. 机器学习算法K-NN的一个使用实例:预测一个人是否患有糖尿病 (KNN-Predict whether a person will have diabetes or not )

    学习中...不断更新. 在糖尿病人的数据库中有几列是不能为0的 比如葡萄糖 胰岛素 身体指数和皮肤厚度.所以在数据预处理阶段需要对这些列的数据进行替换. remeber we did 12 minus ...

  2. dropout含义与原理

    含义 在训练过程中,对神经网络单元按照一定比例暂时将其丢弃. 原理 由于网络参数过多,训练数据少,或者训练次数过多,会产生过拟合的现象.dropout产生的一个重大原因就是为了避免过拟合. 每一层的神 ...

  3. 使用Rabbit MQ消息队列

    使用Rabbit MQ消息队列 综合概述 消息队列 消息队列就是一个消息的链表,可以把消息看作一个记录,具有特定的格式以及特定的优先级.对消息队列有写权限的进程可以向消息队列中按照一定的规则添加新消息 ...

  4. Python函数或者类的时间参数的默认值设为datetime.date.today()引起的问题

    定义了函数def main(start_date=datetime.date.today(), end_date=datetime.date.today()): pass 函数在项目启动后, end_ ...

  5. K8S从入门到放弃系列-(10)kubernetes集群之kube-proxy部署

    摘要: kube-proxy的作用主要是负责service的实现,具体来说,就是实现了内部从pod到service和外部的从node port向service的访问 新版本目前 kube-proxy ...

  6. Hadoop配置环境变量Program~2的用法

    [学习笔记] 3)配置环境变量:(环境变量中的~1,~2,~3的用法)i)JAVA_HOME:注意C:\Program Files目录存在空格,变成C:\Progra~1\Java\jdk1.8.0_ ...

  7. 《Mysql - 字符串索引应该如何建立?》

    一:概述 - 我有一个需求是需要邮箱登录的, - mysql> select f1, f2 from SUser where email='xxx'; - 我们知道,如果不在 email 上建立 ...

  8. python学习-26 函数作用域

    举例说明: 1. name = 'john' def foo(): name = 'xiaomming' def bar(): print(name) return bar a=foo() print ...

  9. Thrift RPC Golang、C++ Example

    Thrift RPC Example 运行 请直接使用即可,无需拉取任何依赖包. cd $GOPATH/src git clone https://github.com/hunterhug/thrif ...

  10. poj 3617 弱鸡贪心

    比赛的时候扣了一道贪心的题目,不会写,,现在补一补一些基础的贪心. 题意:给定一个字符串s,要求按下列操作生成一个新串t--每次从s串中的最前和最后取一个字符给t,要求生成的t字典序最小. 题解:由于 ...