Location: Asia Pacific, Cyberspace, in the Dark Dystopia
Posts: 19,118
Thanks Given: 2,351
Thanked 3,359 Times in 1,878 Posts
Turning jQuery Code into Vue.js
The following is some code I am working on the replace our navbar (someday) with a Vue component.
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:
I see from the source in the test page link you sent that vbuserId and vbtheURL are both already in scope as Javascript variables, which means you can add them to your data function:
And then you can use them in your GetAvatar function:
I guess you need for modify this...
to:
Location: Asia Pacific, Cyberspace, in the Dark Dystopia
Posts: 19,118
Thanks Given: 2,351
Thanked 3,359 Times in 1,878 Posts
Thanks Scott... Sorry, I cannot get your suggestions to work.
This "almost" works:
But the above code only works for the "theicon" text case in the v-html bindings .... if I change it to "theavatar" in the v-html bindings, it breaks.
In this code, the conditional works based on the vbuserId computed to id in vue.... but the problem that remains is that the "theavatar" case, breaks vue when it does the v-html binding.
The problem in the end was in the vB Template, where $jsGlobalsfromvB was given after the Vue components were loaded, meaning that vbuserId and vbtheURL were not set at the time the components were rendered.
Location: Asia Pacific, Cyberspace, in the Dark Dystopia
Posts: 19,118
Thanks Given: 2,351
Thanked 3,359 Times in 1,878 Posts
Thanks Scott,
On a number of occasions I have had trouble with the order of execution of included Javascript file.
Looking back, it seems obvious that the JS vars from vB global_start should have been before the Vue files. That also seem to explain why I could get it to work as a computed property before.
Thanks for your help sorting this out!
Much appreciated!
Now, I need to figure out why the HTML layout is different between the two conditions (guest vs. logged in user)..... That should be an easy CSS issue (update: confirmed CSS fixed).
Location: Asia Pacific, Cyberspace, in the Dark Dystopia
Posts: 19,118
Thanks Given: 2,351
Thanked 3,359 Times in 1,878 Posts
OK... here is the cleaned up code for this header component for the navbar:
Vue.js:
CSS:
Not sure if it a good idea to use the userid in the client-side code for security reasons, but it's worth a thought. Since the userid is only used to determine which panel is opened and which icon to show, it might be worth a bit of hacking in the dev console to see how this could be exploited.
Otherwise, the main goal of moving the jQuery to Vue.js has been accomplished (thanks and hats off to Scott for helping) and this demo header component for a navbar is basically done. Next would be to move the navbar menu to a Vue.js component and to also move the panels in the header to Vue components.
Obviously, it is much easier to design a new web site from the beginning with Vue other than trying to retrofit the old site into Vue; but on the other hand, having an existing site to modify does provide opportunities to improve the site along the way.
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)
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)
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)
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)
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)
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)