009——VUE中watch监听属性变化实现类百度搜索栏功能

2023-02-18,,,,

<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>watch监听属性变化实现类百度搜索功能</title>
<script src="vue.js"></script>
<script src="node_modules/axios/dist/axios.js"></script>
</head>
<body>
<div id="lantian">
<input type="text" v-model="word"/>
<h1>
结果:{{result}}
</h1>
</div>
<script>
var app = new Vue({
el: '#lantian',
watch: {
word: function (newV, oldV) {
//console.log(newV+'=>'+oldV);//输出:新值和旧值
//使用axios发送请求,需要安装node.js。在使用:npm install axios 安装axios
axios.get('9.php?word=' + newV).then(function (response) {
console.log(response);
app.result=response.data;
});
}
},
data: {
word: '',
result: ''
}
});
</script>
</body>
</html>

  9.php中的代码:

<?php
echo "你搜索的内容是:".$_GET['word'];

  

009——VUE中watch监听属性变化实现类百度搜索栏功能的相关教程结束。

《009——VUE中watch监听属性变化实现类百度搜索栏功能.doc》

下载本文的Word格式文档,以方便收藏与打印。