在线观看不卡亚洲电影_亚洲妓女99综合网_91青青青亚洲娱乐在线观看_日韩无码高清综合久久

鍍金池/ 問答/HTML/ vue組件里input綁定v-model為什么會(huì)報(bào)錯(cuò)?

vue組件里input綁定v-model為什么會(huì)報(bào)錯(cuò)?

組件沒有提出來,都寫在一個(gè)文件里的

// index.js

// Login組件里的第一個(gè) input 綁定了一個(gè) v-model='username'
const Login = { template: '<form class="form login"><h2>登陸</h2><input v-model="username" type="username" class="form-control" placeholder="username" required autofocus><input class="form-control" type="password" placeholder="Password" required><button type="submit">登陸</button></form>' }
const SignUp = { template: '<form class="form signup"><h2>注冊(cè)新用戶</h2><input type="username" id="inputUsername" class="form-control" placeholder="username" required autofocus><input type="password" id="inputPassword" class="form-control" placeholder="Password" required><input type="email" id="inputEmail" class="form-control" placeholder="Email address" required><button type="submit">注冊(cè)</button></form>' }

const routes = [
  { path: '/', component: Login },
  { path: '/login', component: Login },
  { path: '/signUp', component: SignUp }
]

const router = new VueRouter({
  routes 
})

// 在data里面也有 username
const app = new Vue({
  router,
  data: {
      username: ''
  }
}).$mount('#app')

為什么會(huì)報(bào)錯(cuò):

clipboard.png

去掉 v-model='username' 和 data 是能夠正常運(yùn)行的
如果我想獲取 input 里用戶輸入的值應(yīng)該怎么做呢

回答
編輯回答
吃藕丑

type="username"應(yīng)該是這個(gè)報(bào)錯(cuò)了。把這個(gè)刪掉試試。data里面的username應(yīng)該就是input的value。

2017年7月7日 15:39
編輯回答
歆久

你需要在Login里面聲明data才行

2017年10月3日 03:10
編輯回答
失魂人

報(bào)錯(cuò)就是屬性或者方法"username"未定義,那估計(jì)就是input的type值username未定義

2017年4月23日 14:03
編輯回答
陪我終

每個(gè)組件內(nèi)部,對(duì)應(yīng) data,需要對(duì)象里面設(shè)置 data 屬性。

const Login = {data(){return {username:""}},template: ...
2017年12月2日 04:09