这是IDEA的后端代码
你都说axios了 当然是给后端传值, 让后端给你返回了
不知道你这个问题是否已经解决, 如果还没有解决的话:App.Vue,内置router-link,可以跳转呈现Component
// App.Vue
<template>
<div>
<router-link :to="/Component">Component</router-link>
<router-view></router-view>
</div>
</template>
Component.Vue,在创建时,使用setInterval
创建1s中的循环动作,在动作中使用Axios获取后端数据
// Component.Vue
<template>
<div></div>
</template>
<script>
export default {
created() {
// 设置一个间隔1s就进行的动作
setInterval(() => {
Axios.get("/data").then((res) => {
// 业务逻辑
})
}, 1000)
}
}
</script>
针对使用Vue和axios实现模糊搜索这个问题,可以采用以下步骤:
data() {
return {
inputVal: '',
results: []
}
}
methods: {
search: function() {
var self = this;
axios.get('/search', {
params: { keyword: self.inputVal }
}).then(function(response) {
self.results = response.data;
});
}
}
上述代码中,首先获取到用户输入的关键字inputVal
,然后使用axios发送一个get请求到后端的/search
路径,同时在请求中带上关键字参数。最后,通过then
方法获取到后端返回的搜索结果,并将结果赋值到results
属性中。
<input v-model="inputVal" type="text">
<button @click="search">Search</button>
上述代码中,搜索框的输入值使用v-model
指令与组件中的inputVal
属性绑定在一起,当用户在搜索框内输入信息时,该数据会自动更新到inputVal
属性中。同时,我们在搜索按钮上的点击事件中调用了search
方法,从而触发搜索操作。
LIKE
关键字实现模糊匹配,例如:SELECT * FROM products WHERE name LIKE '%keyword%';
上述SQL语句中,%
表示可以匹配任意数量的任意字符,因此在执行SQL语句之前,我们需要将框架接收到的keyword
参数前后添加上%
符号,再使用该关键字进行匹配。
总体来说,实现模糊搜索的步骤如下:
LIKE
关键字实现匹配。