<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>

  

最新文章

  1. linux内核(kernel)版本号的意义
  2. SDWebImage 加载网络图片失败,重新运行,就能加载成功。
  3. jacob 多个web项目报错 jacob-1.14.3-x64.dll already loaded in another classloader jacob
  4. innodb insert buffer 插入缓冲区的理解
  5. 【BZOJ3504】危桥(最大流)
  6. 【wikioi】1191 数轴染色(线段树+水题)
  7. Android 监听键盘的弹起与收缩
  8. Oracle使用goldengate分别向Oracle和mysql双路的单向复制
  9. IOS详解TableView——对话聊天布局的实现
  10. apply/call/bind和this的使用
  11. 瓦片切图工具gdal2tiles.py改写为纯c++版本
  12. 搭建idea下的vue工程
  13. Sql Server中sql语句自己主动换行
  14. 加密入门(三):TrueCrypt(转)
  15. Python Extension Packages 下载
  16. zw版【转发&#183;台湾nvp系列Delphi例程】HALCON HistoToThresh1
  17. Hibernate 中的锁( locking )
  18. JS判定注册表单的几个方式 及 Ajax进行用户名存在判定
  19. CTF中的变量覆盖漏洞
  20. AspNet.WebAPI.OData.ODataPQ实现WebAPI的分页查询服务-(个人拙笔)(转)

热门文章

  1. Java实现回形数,只利用数组、循环和if-else语句
  2. www.zhaoyueyi.cn
  3. 排序算法的实现之Javascript(常用)
  4. MySQL 事务一览
  5. golang 切片扩容, 时间复杂度
  6. RabbitMQ的安装(Windows环境下)
  7. [转帖]详解shell脚本括号区别--$()、$「 」、$「 」 、$(()) 、「 」 、「[ 」]
  8. 给出一个javascript的Helloworld例子
  9. 什么是SSH 以及常见的ssh 功能
  10. TypeScript 高级类型 接口(interface)