账号密码登录
微信安全登录
微信扫描二维码登录

登录后绑定QQ、微信即可实现信息互通

手机验证码登录
找回密码返回
邮箱找回 手机找回
注册账号返回
其他登录方式
分享
  • 收藏
    X
    怎样使用localStorage保存页面中Vue渲染的列表,页面刷新后还原为之前的页面
    41
    0

    <!DOCTYPE html>
    <html>
    <head>

    <meta charset="UTF-8">
    <title>Title</title>
    <script src="dist/vue.js"></script>
    <script type="text/javascript" src="https://cdn.bootcss.com/vue-resource/1.3.4/vue-resource.min.js"></script>
    <script src="dist/vuex.min.js"></script>
    <style>
        .mseeage{
            width: 800px;
            height: 60px;
            float: right;
        }
        .answer{
            width: 800px;
            height: 60px;
            float: left;
        }
    </style>

    </head>
    <body>
    <div id="box">

     <div v-for="item in $store.state.cartList"  >
          <p class="mseeage">{{ item.message }}<img src="images/tx1.jpg"></p>
          <p class="answer"><img src="images/tx2.jpg">{{ item.answer}}</p>
      </div>
     <div><input  v-model="message"><button id="save" @click="info()">发送</button></div>

    </div>
    <script>

    const store =    new Vuex.Store({
        state:{
            cartList:[]//是记录用户列表状态
        },
        mutations:{
            setTalk(state,info){
                state.cartList.push(info)
            }
        }
    })
    var example1 = new Vue({
        el: '#box',
        data(){
            return{
                message:[],
                answer:[]
            }
        },
        methods:{
          info(){
              this.$http.get('http://www.tuling123.com/openapi/api?key=72d6117e0eef403c95c9aebe73a07e6a' + '&info=' + this.message)
                  .then(function (response) {
                      console.log(response.body.text);
                      this.answer = response.body.text;
                      store.commit('setTalk',{
                          message:this.message,
                          answer:this.answer,
                      });
                  });
            }
        },
        store
    })

    </script>
    </body>
    </html>

    0
    打赏
    收藏
    点击回答
        全部回答
    • 共 0 条
    更多回答
    扫一扫访问手机版
    • 回到顶部
    • 回到顶部