阅读背景:

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

来源:互联网 
<!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>
<!DOCTYPE html>
<html>
<head>
    <meta cha



你的当前访问异常,请进行认证后继续阅读剩余内容。

分享到: