我正在为我的 SpringBoot 应用程序创建前端。要发送 Get 请求,我需要从程序中的输入获取值,但没有成功。
\n\n选择后我尝试使用任何.value, valueOf(),方法之王.toString()document.getElementById("name"),但它们似乎都不起作用。
// 元素
\n\n<form class="pt-3">\n <div class="form-group">\n <label for ="name">Person ID</label>\n <input\n type="text"\n id="name"\n class="form-control is"\n :class="{\'is-invalid\': $v.name.$error} "\n @input="$v.name.$touch()"\n v-model="name"\n placeholder="123456"\n value=""\n >\n <div class="invalid-feedback" v-if="!$v.name.minLength">ID must be at least 5 characters</div>\n <button class="btn btn-secondary btn-lg btn-block" @click="FetchData">\xd0\x9d\xd0\xb0\xd0\xb9\xd1\x82\xd0\xb8</button>\n </div> \n</form>\nRun Code Online (Sandbox Code Playgroud)\n\n// 功能
\n\nAddPerson: function () {\n var nperson = document.getElementById("name").valueOf().value.name;\n console.log(nperson);\n}\nRun Code Online (Sandbox Code Playgroud)\n\n我需要将用户输入的文本输出到页面上的名称行并将其发布到console.log().
/// 添加
\n\ndata() {\n return …Run Code Online (Sandbox Code Playgroud) 我正在构建一个具有文件输入字段并通过以下函数呈现的组件VueJs:
export default {
name: 'nits-file-input',
props: {
label: String,
},
render (createElement) {
return createElement('div', { class: 'form-group m-form__group'}, [
createElement('label', this.label),
createElement('div'),
createElement('div', { class: 'custom-file'},[
createElement('input', {
class: 'custom-file-input',
attrs: { type: 'file' },
domProps: {
value: self.value
},
on: {
input: (event) => {
var reader = new FileReader()
reader.readAsDataURL(event.target.value)
reader.onload = function () {
console.log(reader.result);
};
this.$emit('input', event.target.value)
}
}
}),
createElement('label', { class: 'custom-file-label'}, 'Choose File')
])
])
}
}
Run Code Online (Sandbox Code Playgroud)
虽然在 v-model …
我正在玩vue js和第三方API。我已经成功获取了json数据并将其呈现在html中,但是我在图像上苦苦挣扎。json文件中缺少某些图像,因此我将其本地存储在笔记本电脑中。
我试图在我的html中使用v-if设置空图像源,但没有运气。(请参阅我的html文件中的注释)
另外,我尝试为每个类分配一个类img,然后尝试img使用jquery 设置源,$("#zTTWa2").attr("src", "missing_beers-logo/11.5%20plato.png");但也没有运气。
我的错在哪里 也许我的方法是完全错误的,因为我是编码方面的新手,任何建议将不胜感激。先感谢您
var app = new Vue({
el: "#app",
data: {
beers: [],
decrArray: [], //array with img links
cleanedArray: [], //without undefined
path: 0,
images: [missing_beers-logo/11.5%20plato.png", "missing_beers-logo/11.5%20plato.png", "missing_beers-logo/11.5%20plato.png", "missing_beers-logo/11.5%20plato.png", "missing_beers-logo/11.5%20plato.png", "missing_beers-logo/11.5%20plato.png", "missing_beers-logo/11.5%20plato.png", "missing_beers-logo/11.5%20plato.png",
"missing_beers-logo/11.5%20plato.png", "missing_beers-logo/11.5%20plato.png", "missing_beers-logo/11.5%20plato.png", "missing_beers-logo/11.5%20plato.png", "missing_beers-logo/11.5%20plato.png", "missing_beers-logo/11.5%20plato.png", "missing_beers-logo/11.5%20plato.png", "missing_beers-logo/11.5%20plato.png", "missing_beers-logo/11.5%20plato.png",
"missing_beers-logo/11.5%20plato.png", "missing_beers-logo/11.5%20plato.png", "missing_beers-logo/11.5%20plato.png", "missing_beers-logo/11.5%20plato.png"],
created: function() {
this.getData();
},
methods: {
getData: function() {
var fetchConfig =
fetch("http://api.brewerydb.com/v2/beers?key=6a3ac324d48edac474417bab5926b70b&format=json", {
method: "GET", …Run Code Online (Sandbox Code Playgroud)我正在使用 Vuetify 组件v-checkbox。
我想为复选框的真/假状态指定特定值。
查看文档,我似乎可以使用true-value&false-value属性来做到这一点。
<v-checkbox
v-else-if="input.type == 'checkbox'"
false-value="0"
true-value="1"
input-value="input.val"
:error-messages="form.errors[field]"
>
<template #label>@{{ input.hint }}</template>
</v-checkbox>
Run Code Online (Sandbox Code Playgroud)
但是,使用上面的示例不会提交1选中复选框时的值。0无论复选框是否被选中,该复选框都会提交。
我需要做什么才能正确设置true-valueto 1?
我开始使用 Vuetify 2.x。
我有一个表格,一些列应该用 html 显示。
所以我使用了下面的代码:
<v-data-table
:headers="headers"
:items="decorations"
:items-per-page-options="[20]"
class="elevation-1"
>
<template v-slot:items="props">
<tr>
<td class="text-sm-center">{{ props.item.name}}</td>
<td><span v-html="props.item.desc"></span></td>
</tr>
</template>
</v-data-table>
Run Code Online (Sandbox Code Playgroud)
但是从 Vuetify 2.0 开始,表已经改变了。
<v-data-table
:headers="headers"
:items="decorations"
:items-per-page-options="[20]"
class="elevation-1"
>
</v-data-table>
Run Code Online (Sandbox Code Playgroud)
不再使用“模板”。所以我不知道如何在某些列中应用“v-html”。
使用Options API,我像这样验证了我的表单:
模板:
<v-form ref="form" v-model="valid" lazy-validation @submit.prevent>
...
Run Code Online (Sandbox Code Playgroud)
脚本:
methods: {
validate() {
this.$refs.form.validate();
...
}
}
Run Code Online (Sandbox Code Playgroud)
现在,使用 new Composition API,我如何调用validate()表单?
请看这两个代码片段,它们都输出相同的结果:
<template>
<input type="file" @input="input" />
</template>
<script>
export default {
methods: {
input(event) {
console.log(event.target.files);
},
},
};
</script>
Run Code Online (Sandbox Code Playgroud)
<template>
<input type="file" @change="change" />
</template>
<script>
export default {
methods: {
change(event) {
console.log(event.target.files);
},
},
};
</script>
Run Code Online (Sandbox Code Playgroud)
element@input和@changeevent之间有什么区别<input type="file" />吗?
基本上,标题已经说明了一切:In Vue.js 3, Why do I have to use the valueproperty on ref, but not onreactive?
我知道这ref是针对简单值,例如布尔值、数字、\xe2\x80\xa6,并且reactive针对复杂值,例如对象和数组。我不明白的是:
value何时访问 aref的值,但如果使用 则不需要指定reactive?这不是 API 中的不一致吗?或者是否存在实际的技术原因??我认为我错过了一些东西,但事实并非如此。有人可以帮忙吗?
\n在使用 Vue CLI 4.5.x 时,我尝试了以下代码:
import Vue from "vue"
import App from './App.vue'
new Vue({
el: "#app",
render: h=> h(App)
})
Run Code Online (Sandbox Code Playgroud)
但不幸的是,它给出了以下警告:
"export 'default' (imported as 'Vue') was not found in 'vue'
我可以从中得出的结论是,Vue CLI 4.5.x 已经停止了这种首先创建 Vue 实例的应用程序创建方式。
初始化主应用程序,官方的方式如下:
import { createApp } from 'vue'
import App from './App.vue'
createApp(App).mount('#app')
Run Code Online (Sandbox Code Playgroud)
我不确定我的结论是否正确。如果有人能具体说明我的结论,那将是一个很大的帮助,因为到目前为止我还没有在 vue 的官方文档中找到任何证据。
此外,后面的代码是使用 Vue CLI 4.5.* 应用程序实例烘焙的,而前面的代码在使用 CDN 时是正确的。
考虑这个基本示例,其中我们有一个input和 ap显示输入的值:
const App = {
data() {
return {
message: "hello world!"
};
}
};
Vue.createApp(App).mount('#root');Run Code Online (Sandbox Code Playgroud)
<script src="https://unpkg.com/vue@next"></script>
<div id="root">
<input v-model="message"/>
{{ message }}
</div>Run Code Online (Sandbox Code Playgroud)
当您更改输入文本时,它会反映在p. 但是,如果您替换data()为setup(),则对 的更改input不再反映在p:
const App = {
setup() {
return {
message: "hello world!"
};
}
};
Vue.createApp(App).mount('#root');Run Code Online (Sandbox Code Playgroud)
<script src="https://unpkg.com/vue@next"></script>
<div id="root">
<input v-model="message"/>
{{ message }}
</div>Run Code Online (Sandbox Code Playgroud)
一个简单的解决方法是ref在message:
const App = {
setup() { …Run Code Online (Sandbox Code Playgroud)vue.js ×10
javascript ×7
vuejs2 ×7
vuejs3 ×4
vuetify.js ×3
bootstrap-4 ×1
html ×1
vue-cli-4 ×1