• <i id='yqEdx'><tr id='yqEdx'><dt id='yqEdx'><q id='yqEdx'><span id='yqEdx'><b id='yqEdx'><form id='yqEdx'><ins id='yqEdx'></ins><ul id='yqEdx'></ul><sub id='yqEdx'></sub></form><legend id='yqEdx'></legend><bdo id='yqEdx'><pre id='yqEdx'><center id='yqEdx'></center></pre></bdo></b><th id='yqEdx'></th></span></q></dt></tr></i><div id='yqEdx'><tfoot id='yqEdx'></tfoot><dl id='yqEdx'><fieldset id='yqEdx'></fieldset></dl></div>
    • <bdo id='yqEdx'></bdo><ul id='yqEdx'></ul>
    <tfoot id='yqEdx'></tfoot>

  • <legend id='yqEdx'><style id='yqEdx'><dir id='yqEdx'><q id='yqEdx'></q></dir></style></legend>

      <small id='yqEdx'></small><noframes id='yqEdx'>

        Vue.js 中如何在父孙之间进行双向数据绑定

        时间:2023-09-30
        • <bdo id='kgqLX'></bdo><ul id='kgqLX'></ul>
            <tbody id='kgqLX'></tbody>
        • <legend id='kgqLX'><style id='kgqLX'><dir id='kgqLX'><q id='kgqLX'></q></dir></style></legend>
          <tfoot id='kgqLX'></tfoot>
            <i id='kgqLX'><tr id='kgqLX'><dt id='kgqLX'><q id='kgqLX'><span id='kgqLX'><b id='kgqLX'><form id='kgqLX'><ins id='kgqLX'></ins><ul id='kgqLX'></ul><sub id='kgqLX'></sub></form><legend id='kgqLX'></legend><bdo id='kgqLX'><pre id='kgqLX'><center id='kgqLX'></center></pre></bdo></b><th id='kgqLX'></th></span></q></dt></tr></i><div id='kgqLX'><tfoot id='kgqLX'></tfoot><dl id='kgqLX'><fieldset id='kgqLX'></fieldset></dl></div>

            <small id='kgqLX'></small><noframes id='kgqLX'>

                  本文介绍了Vue.js 中如何在父孙之间进行双向数据绑定的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  我遇到了一个问题,我通过 cookie 解决了它,但我想在没有 cookie 的情况下解决问题.我有一个名为 app-header 的组件,它还有另一个名为 outmodal 的组件.现在,我的第一个 Vue 实例需要组件 app-header.

                  I faced a problem, I solve it by cookies but I want to solve the problem without cookies. I have a component which called app-header and It has another component which called outmodal. Now, My first Vue instance require component app-header.

                  var vue = new Vue({
                      el : "html",
                      data : {
                          title       : "Site Title",
                          description : "description of page",
                          keywords    : "my keywords",
                          view        : "home",
                          login       : "login"
                      },
                      components:{
                          "app-header" :require("../../components/header"),
                          "app-footer" :require("../../components/footer"),
                          "home"       :require("../../views/home")
                      },
                  });
                  

                  app-header 代码

                  code of app-header

                  var Vue     = require("vue");
                  
                  Vue.partial("login",require("../../partials/login.html"));
                  Vue.partial("logged",require("../../partials/logged.html"));
                  
                  module.exports = {
                      template    : require("./template.html"),
                      replace     : true,
                      components  : {
                          outmodal : require("../outmodal")
                      },
                      props : ['login']
                  }
                  

                  模态代码

                  var Vue = require("vue");
                  Vue.partial("loginModal",require("../../partials/loginModal.html"));
                  
                  module.exports = {
                      template    : require("./template.html"),
                      replace     : true,
                      props       : ['name'],
                      data        : function () {
                              return  {
                                  userLogin : { mail  :   "", password    :   "", remember    :   ""}
                              }
                  
                      },
                      methods : {
                          formSubmit : function(e){
                                  e.preventDefault();
                                  this.$http.post("http://example.com/auth/login",{ "email": this.userLogin.mail , "password": this.userLogin.password },function(data,status,request){
                                      $.cookie("site_token",data.token,{expires : 1})
                                  }).error(function(data,status,request){
                  
                                  });
                  
                          }
                      }, ready  : function(){
                          console.log("it works")
                      }
                  }
                  

                  在 outmodal 组件中,我连接 API 并检查登录,如果登录成功,我想更改 Vue 实例中登录变量的值.我使用 web pack 来构建所有需求.所以我不知道如何在这些文件之间进行数据绑定.

                  In outmodal component I connect the API and I check the login, If login will be succesfull, I want to change value of login variable in my Vue instance. I use web pack to build all requires. So I don't know how can I data binding between these files.

                  我该如何解决?我

                  推荐答案

                  我找到的最佳解决方案

                  对于 0.12

                  http://012.vuejs.org/guide/components.html#Inheriting_Parent_Scope

                  1.0

                  http://v1.vuejs.org/guide/components.html#Parent-Child-Communication

                  对于 2.0

                  https://vuejs.org/v2/guide/components.html#Composing-Components(使用 props 将数据从父级单向绑定到子级)

                  https://vuejs.org/v2/guide/components.html#Composing-Components (use props to one-way bind data from parent to child)

                  这篇关于Vue.js 中如何在父孙之间进行双向数据绑定的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  上一篇:如何使用 Vue 命名插槽呈现静态内容列表? 下一篇:Angular 2中的禁用按钮

                  相关文章

                  1. <i id='WCHIr'><tr id='WCHIr'><dt id='WCHIr'><q id='WCHIr'><span id='WCHIr'><b id='WCHIr'><form id='WCHIr'><ins id='WCHIr'></ins><ul id='WCHIr'></ul><sub id='WCHIr'></sub></form><legend id='WCHIr'></legend><bdo id='WCHIr'><pre id='WCHIr'><center id='WCHIr'></center></pre></bdo></b><th id='WCHIr'></th></span></q></dt></tr></i><div id='WCHIr'><tfoot id='WCHIr'></tfoot><dl id='WCHIr'><fieldset id='WCHIr'></fieldset></dl></div>
                    <tfoot id='WCHIr'></tfoot>
                      <bdo id='WCHIr'></bdo><ul id='WCHIr'></ul>
                    <legend id='WCHIr'><style id='WCHIr'><dir id='WCHIr'><q id='WCHIr'></q></dir></style></legend>

                    <small id='WCHIr'></small><noframes id='WCHIr'>