javascript - 我如何从在 to a method in my export default in Vue?
I'm trying to collect the text from a text input in HTML to the methods section of my Vue file but can't seem to figure it out. I've spent a couple hours researching v-mode
问题描述
I'm trying to collect the text from a text input in HTML to the methods section of my Vue file but can't seem to figure it out. I've spent a couple hours researching v-model and messing around with it but, I was either doing it wrong or it doesn't do what I thought it did. Here's my code:
<template>
<div id="app">
<Layout>
<input id="queryBox" placeholder="Enter your SQL query here." size="60"/>
<br>
<input type="submit" v-on:click="logSomething()">
</Layout>
</div>
</template>
<script>
export default {
data: () => {
return {
queryText: ""
}
},
methods: {
logSomething() {
console.log(this.queryBox)
}
}
}
</script>
I'm trying to send whatever the user inputs into queryBox to the logSomething() method upon the click of the submit button. Thanks in advance for any help!
Difference between single and double bracket in calling columns
I'm in the process of learning R and hoped for some clarification on something.
Given this dataframe:
myDataset <- data.frame("IDs" = rep(1:10,each = 5),
"session" = rep(1:5, times = 10),
"IV" = rnorm(50),
"DV" = rnorm(50))
What different uses would calling the first column from this dataframe have based on whether you used one set of brackets:
myDataset[1]
Or two sets of brackets:
myDataset[[1]]
They both give the same information, one in the form of the numbers listed in rows and the other in its original column form.
I'm just trying to understand why I might want to use one over the other.
解决方案
您可以使用 v-model 并映射queryText
包含输入字段数据的变量。然后在点击时,使用事件并使提交不加载表单,只是为了避免加载页面。
<template>
<div id="app">
<Layout>
<input id="queryBox" v-model="queryText" placeholder="Enter your SQL query here." size="60"/>
<br>
<input type="submit" v-on:click="logSomething">
</Layout>
</div>
</template>
<script>
export default {
data: () => {
return {
queryText: ""
}
},
methods: {
logSomething(e) {
e.preventDefault()
console.log(this.queryText)
}
}
}
</script>
推荐阅读
- java - DateFormatter 错误地打印了日期(Java)
- elasticsearch - Elasticsearch中的关键字匹配(精确匹配)忽略关键字的顺序
- c - 如何检查输入何时超过二维数组列中的行?
- git - Azure DevOps - 如何通过 git commit 更改工作项的状态
- google-cloud-platform - 在大查询中将多行转换为单个键值对行/列
- c++ - Win32 API 调用引发访问冲突
- sumo - 如何在 SUMO 或 FLOW 中实现红绿灯的最长队列优先规则?
- python - 导入的 python xarray 模块的属性不起作用
- api - 在发布请求中将密码视为纯文本是很常见的吗?
- python - 没有从 describe_images 获取信息?
I'm trying to collect the text from a text input in HTML to the methods section of my Vue file but can't seem to figure it out. I've spent a couple hours researching v-mode
问题描述
I'm trying to collect the text from a text input in HTML to the methods section of my Vue file but can't seem to figure it out. I've spent a couple hours researching v-model and messing around with it but, I was either doing it wrong or it doesn't do what I thought it did. Here's my code:
<template>
<div id="app">
<Layout>
<input id="queryBox" placeholder="Enter your SQL query here." size="60"/>
<br>
<input type="submit" v-on:click="logSomething()">
</Layout>
</div>
</template>
<script>
export default {
data: () => {
return {
queryText: ""
}
},
methods: {
logSomething() {
console.log(this.queryBox)
}
}
}
</script>
I'm trying to send whatever the user inputs into queryBox to the logSomething() method upon the click of the submit button. Thanks in advance for any help!
Difference between single and double bracket in calling columns
I'm in the process of learning R and hoped for some clarification on something.
Given this dataframe:
myDataset <- data.frame("IDs" = rep(1:10,each = 5),
"session" = rep(1:5, times = 10),
"IV" = rnorm(50),
"DV" = rnorm(50))
What different uses would calling the first column from this dataframe have based on whether you used one set of brackets:
myDataset[1]
Or two sets of brackets:
myDataset[[1]]
They both give the same information, one in the form of the numbers listed in rows and the other in its original column form.
I'm just trying to understand why I might want to use one over the other.
解决方案
您可以使用 v-model 并映射queryText
包含输入字段数据的变量。然后在点击时,使用事件并使提交不加载表单,只是为了避免加载页面。
<template>
<div id="app">
<Layout>
<input id="queryBox" v-model="queryText" placeholder="Enter your SQL query here." size="60"/>
<br>
<input type="submit" v-on:click="logSomething">
</Layout>
</div>
</template>
<script>
export default {
data: () => {
return {
queryText: ""
}
},
methods: {
logSomething(e) {
e.preventDefault()
console.log(this.queryText)
}
}
}
</script>
推荐阅读
- java - DateFormatter 错误地打印了日期(Java)
- elasticsearch - Elasticsearch中的关键字匹配(精确匹配)忽略关键字的顺序
- c - 如何检查输入何时超过二维数组列中的行?
- git - Azure DevOps - 如何通过 git commit 更改工作项的状态
- google-cloud-platform - 在大查询中将多行转换为单个键值对行/列
- c++ - Win32 API 调用引发访问冲突
- sumo - 如何在 SUMO 或 FLOW 中实现红绿灯的最长队列优先规则?
- python - 导入的 python xarray 模块的属性不起作用
- api - 在发布请求中将密码视为纯文本是很常见的吗?
- python - 没有从 describe_images 获取信息?