0
votes

I Am using vuejs for design purpose,I want when i click on login button it will open my dashboard but i cant do that ,because i am new to vue js here below my codes Error in v-on handler: "TypeError: Cannot read property 'CForm' of null"

vue.esm.js?a026:1897 TypeError: Cannot read property 'CForm' of null at click (eval at ./node_modules/cache-loader/dist/cjs.js?{"cacheDirectory":"node_modules/.cache/vue-loader","cacheIdentifier":"0b619c3d-vue-loader-template"}!./node_modules/vue-loader/lib/loaders/templateLoader.js?!./node_modules/cache-loader/dist/cjs.js?!./node_modules/vue-loader/lib/index.js?!./src/views/pages/Login.vue?vue&type=template&id=07b13bd8& (34.js:23), :97:73) at invokeWithErrorHandling (vue.esm.js?a026:1863) at HTMLButtonElement.invoker (vue.esm.js?a026:2184) at HTMLButtonElement.original._wrapper (vue.esm.js?a026:7565

)

 Login.vue

    <template>
    <div id="login">
      <CContainer class="d-flex content-center min-vh-100">
        <CRow>
          <CCol>
            <CCardGroup>
              <CCard class="p-4">
                <CCardBody>
                  <CForm>
                    <h1>Login</h1>
                    <p class="text-muted">Sign In to your account</p>
                    <CInput
                     name:username
                      placeholder="Username"
                      autocomplete="usernameemail"
                    >
                      <template #prepend-content><CIcon name="cil-user"/></template>
                    </CInput>
                    <CInput
                     name:password
                      placeholder="Password"
                      type="password"
                      autocomplete="curent-password"
                    >
                      <template #prepend-content><CIcon name="cil-lock-locked"/></template>
                    </CInput>
                    <CRow>
                      <CCol col="6" class="text-left">
                        <CButton color="primary" class="px-4" @click="check(this.CForm)">Login</CButton>
                      </CCol>
                      <CCol col="6" class="text-right">
                        <CButton color="link" class="px-0">Forgot password?</CButton>
                        <CButton color="link" class="d-md-none">Register now!</CButton>
                      </CCol>
                    </CRow>
                  </CForm>
                </CCardBody>
              </CCard>
              <CCard
                color="primary"
                text-color="white"
                class="text-center py-5 d-sm-down-none"
                body-wrapper
              >
                <h2>Sign up</h2>
                <p>Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.</p>
                <CButton
                  color="primary"
                  class="active mt-3"
                >
                  Register Now!
                </CButton>
              </CCard>
            </CCardGroup>
          </CCol>
        </CRow>
      </CContainer>
    </div>
    </template>

    <script type="text/javascript">
    export default {
      name: 'Login',
    methods:{
                check(CForm){
               if (CForm.username.value=="demon" && CForm.password.value=="pwr") {
                  window.open("Dashboard.vue")
                } else {
                  alert("wrong email and password")
                }
                }
             }
     }
    </script>
1

1 Answers

0
votes

You cannot open a view with window.open (url).

You can use axios (or similar) to request authentication on your server.

When clicking on the login button: send the login and password with Axios to the server authentication endpoint (for example: www.yourserver / login / connect.php), in POST mode.

Your server will need to authenticate you and return a response. In the view, the answer can be tested in the callback part of the request: a method is provided for this.

If successful : access your dashboard page (window.open ("www.Yourserver / dashboard.php ").

note : the dashboard.php must verify if you are really authorized.

If you use spa logic (single page application). You will use vueroute and probably vuex.js.

I think you need to deepen the concept vue.js / spa application / landing page / vueroute.js / vuex.js / axios (or similar). good luck.