Sponsored Content
Top Forums Web Development Turning jQuery Code into Vue.js Post 303025638 by Neo on Thursday 8th of November 2018 06:30:19 AM
Old 11-08-2018
Turning jQuery Code into Vue.js

The following is some code I am working on the replace our navbar (someday) with a Vue component.

Code:
Vue.component("unix-navbar", {
  template: `<div class="neo-table-border vuenavbar"><div class="flex-item" style="margin-bottom:10px;padding-top:13px;"><a class="vuenavbarhome" :href="url">{{name}}</a></div>
	            <div id="avatar" class="flex-item" v-html="theavatar" v-on:click="OpenMemberPanel()" style="cursor:pointer;" align="center"></div></div>`,
  data() {
    return {
      unixtime: "",
      name: "The UNIX and Linux Forums",
      url: "https://www.unix.com/",
      theavatar:
        '<span  class="alt1" style="font-size:3em;cursor:pointer;float:right;background-color:transparent;margin-right:5px;margin-left:10px;top:0;padding:20px;" ><i style="color:#170072;" class="fas fa-user"></i></span>'
    };
  },
  methods: {
    GetAvatar() {
      if (vbuserId > 0)
        this.theavatar = '<img src="' + vbtheURL + '"  width="60px"></img>';
      else
        this.theavatar =
          '<span  class="alt1" style="font-size:3em;cursor:pointer;float:right;background-color:transparent;margin-right:5px;margin-left:10px;top:0;padding:20px;" ><i style="color:#170072;" class="fas fa-user"></i></span>';
    },
    GetUrl() {
      this.theurl = vbtheURL;
    },
    UpdateTime() {
      this.unixtime = Math.round(new Date().getTime() / 1000);
    },
    OpenMemberPanel() {
      if (vbuserId > 0) openMemberPanel();
      else openLogin();
    }
  },
  created() {
    GetAvatar();
    setInterval(() => {
      this.UpdateTime();
    }, 1000);
  }
});

var navbar =
  new Vue({
    el: "#vue-navbar"
  }) 


  $(function() {
    if (vbtheURL.length > 10)
      $("#avatar").html('<img src="' + vbtheURL + '"  width="60px"></img>');
    else
      $("#avatar").html(
        '<span  class="alt1" style="font-size:3em;cursor:pointer;float:right;background-color:transparent;margin-right:5px;margin-left:10px;top:0;padding:20px;" ><i style="color:#170072;" class="fas fa-user"></i></span>'
      );
  });

Basically, this is working OK; but I used jQuery to make it work.

Does anyone have any suggestions on how to do this using only Vue.js and no jQuery?


OBTW... this methods in the Vue.js code is not being used (or working). That's why I wrote the jQuery code as I could not get the code below to work right in Vue.js:

Code:
GetAvatar() {
      if (vbuserId > 0)
        this.theavatar = '<img src="' + vbtheURL + '"  width="60px"></img>';
      else
        this.theavatar =
          '<span  class="alt1" style="font-size:3em;cursor:pointer;float:right;background-color:transparent;margin-right:5px;margin-left:10px;top:0;padding:20px;" ><i style="color:#170072;" class="fas fa-user"></i></span>';
    },

 

6 More Discussions You Might Find Interesting

1. What is on Your Mind?

JQuery and CSS Flex Code for Responsive WOL Page

I have just wrote this jQuery to the WOL page, so the table of users on line will not need scrollbars and will instead transform into a responsive table: <script> jQuery(document).ready(function (){ jQuery("#neo-who-flex-tcat"). css({"display":"flex","flex-flow":"row wrap", ... (0 Replies)
Discussion started by: Neo
0 Replies

2. What is on Your Mind?

JQuery and CSS Flex Code for Responsive Forum Home Page

So far, I have completed making the home page more responsive (except for the forum stats at the top and the WOL box at the bottom, they still use scroll bars). xevV3_iZ8-s For full screen use the link below and set your YT resolution to 1080p60 HD https://youtu.be/xevV3_iZ8-s Here is... (1 Reply)
Discussion started by: Neo
1 Replies

3. What is on Your Mind?

JQuery to Add Code Tags to Selected Text

Hey. Someone find or write some jQuery code where we can select text with our mouse and then click or double click the highlighted / selected text and then it will wrap code tags around the highlighted text (in our editors). :) (0 Replies)
Discussion started by: Neo
0 Replies

4. Web Development

Simple Vue.js Component to Redirect to External Web Page Using Vue Router

Vue Router has some quirks and on of the quirks is that it is not reliable when adding external links using the vue-router library. After struggling with many solutions, I have found that creating a simple Vue.js component like this one seems to work the best (so far): Component Example: ... (0 Replies)
Discussion started by: Neo
0 Replies

5. Web Development

Vue JS 2 Tutorial by The Net Ninja: A Recommended Vue.js Video Tutorial Series

A number of people have asked me how to get started with Vue.js and my reply before today was to Google "Vue.js". That has changed and my recommendation to anyone who wants to learn the fastest growing, easiest to learn and use Vue.js web dev framework is to watch this video tutorial series: ... (0 Replies)
Discussion started by: Neo
0 Replies

6. Web Development

Vue.js component: Beautiful code highlighter

Sooner than later I will render forum discussions in Vue.js to complement the standard way of showing forum threads. Today, I ran across this component, vue-code-highlight Beautiful code syntax highlighting as Vue.js component. https://www.unix.com/members/1-albums225-picture1199.jpg ... (1 Reply)
Discussion started by: Neo
1 Replies
All times are GMT -4. The time now is 11:47 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy